/*      */ package com.zimbra.cs.account;
/*      */ 
/*      */ import com.google.common.base.Charsets;
/*      */ import com.google.common.collect.HashMultiset;
/*      */ import com.google.common.collect.Multiset;
/*      */ import com.google.common.collect.Multiset.Entry;
/*      */ import com.google.common.collect.Sets;
/*      */ import com.zimbra.common.account.Key.AccountBy;
/*      */ import com.zimbra.common.account.Key.AlwaysOnClusterBy;
/*      */ import com.zimbra.common.account.Key.CacheEntryBy;
/*      */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*      */ import com.zimbra.common.account.Key.CosBy;
/*      */ import com.zimbra.common.account.Key.DataSourceBy;
/*      */ import com.zimbra.common.account.Key.DistributionListBy;
/*      */ import com.zimbra.common.account.Key.DomainBy;
/*      */ import com.zimbra.common.account.Key.ServerBy;
/*      */ import com.zimbra.common.account.Key.SignatureBy;
/*      */ import com.zimbra.common.account.Key.UCServiceBy;
/*      */ import com.zimbra.common.account.Key.XMPPComponentBy;
/*      */ import com.zimbra.common.account.ZAttrProvisioning.AccountStatus;
/*      */ import com.zimbra.common.account.ZAttrProvisioning.DomainType;
/*      */ import com.zimbra.common.auth.ZAuthToken;
/*      */ import com.zimbra.common.localconfig.KnownKey;
/*      */ import com.zimbra.common.localconfig.LC;
/*      */ import com.zimbra.common.net.SocketFactories;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.soap.Element;
/*      */ import com.zimbra.common.soap.SoapHttpTransport;
/*      */ import com.zimbra.common.soap.SoapHttpTransport.HttpDebugListener;
/*      */ import com.zimbra.common.soap.SoapTransport;
/*      */ import com.zimbra.common.util.AccountLogger;
/*      */ import com.zimbra.common.util.ByteUtil;
/*      */ import com.zimbra.common.util.CliUtil;
/*      */ import com.zimbra.common.util.DateUtil;
/*      */ import com.zimbra.common.util.FileUtil;
/*      */ import com.zimbra.common.util.Pair;
/*      */ import com.zimbra.common.util.SetUtil;
/*      */ import com.zimbra.common.util.StringUtil;
/*      */ import com.zimbra.common.util.Version;
/*      */ import com.zimbra.common.util.ZimbraLog;
/*      */ import com.zimbra.common.zclient.ZClientException;
/*      */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*      */ import com.zimbra.cs.account.accesscontrol.AttrRight;
/*      */ import com.zimbra.cs.account.accesscontrol.ComboRight;
/*      */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*      */ import com.zimbra.cs.account.accesscontrol.Help;
/*      */ import com.zimbra.cs.account.accesscontrol.Right;
/*      */ import com.zimbra.cs.account.accesscontrol.Right.RightType;
/*      */ import com.zimbra.cs.account.accesscontrol.RightClass;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.ACE;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.AllEffectiveRights;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.DomainedRightsByTargetType;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveAttr;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveRights;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.Grants;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.RightAggregation;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.RightsByTargetType;
/*      */ import com.zimbra.cs.account.accesscontrol.RightManager;
/*      */ import com.zimbra.cs.account.accesscontrol.RightModifier;
/*      */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*      */ import com.zimbra.cs.account.ldap.LdapEntrySearchFilter;
/*      */ import com.zimbra.cs.account.ldap.LdapProv;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.IndexStatsInfo;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.MailboxInfo;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.MemcachedClientConfig;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.QuotaUsage;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.ReIndexBy;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.ReIndexInfo;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.ReIndexInfo.Progress;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.VerifyIndexResult;
/*      */ import com.zimbra.cs.fb.FbCli;
/*      */ import com.zimbra.cs.fb.FbCli.FbProvider;
/*      */ import com.zimbra.cs.fb.FbCli.FbQueue;
/*      */ import com.zimbra.cs.httpclient.URLUtil;
/*      */ import com.zimbra.cs.ldap.LdapClient;
/*      */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*      */ import com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId;
/*      */ import com.zimbra.cs.mailbox.MailItem.Type;
/*      */ import com.zimbra.cs.util.BuildInfo;
/*      */ import com.zimbra.cs.util.SoapCLI;
/*      */ import com.zimbra.cs.zclient.ZMailboxUtil;
/*      */ import com.zimbra.soap.JaxbUtil;
/*      */ import com.zimbra.soap.admin.message.LockoutMailboxRequest;
/*      */ import com.zimbra.soap.admin.message.UnregisterMailboxMoveOutRequest;
/*      */ import com.zimbra.soap.admin.type.CacheEntryType;
/*      */ import com.zimbra.soap.admin.type.CountObjectsType;
/*      */ import com.zimbra.soap.admin.type.DataSourceType;
/*      */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*      */ import com.zimbra.soap.admin.type.MailboxMoveSpec;
/*      */ import com.zimbra.soap.type.AccountNameSelector;
/*      */ import com.zimbra.soap.type.GalSearchType;
/*      */ import com.zimbra.soap.type.TargetBy;
/*      */ import java.io.BufferedReader;
/*      */ import java.io.BufferedWriter;
/*      */ import java.io.File;
/*      */ import java.io.FileInputStream;
/*      */ import java.io.IOException;
/*      */ import java.io.InputStream;
/*      */ import java.io.InputStreamReader;
/*      */ import java.io.OutputStreamWriter;
/*      */ import java.io.PrintStream;
/*      */ import java.io.UnsupportedEncodingException;
/*      */ import java.text.DateFormat;
/*      */ import java.text.SimpleDateFormat;
/*      */ import java.util.ArrayList;
/*      */ import java.util.Collection;
/*      */ import java.util.Collections;
/*      */ import java.util.Date;
/*      */ import java.util.HashMap;
/*      */ import java.util.HashSet;
/*      */ import java.util.Iterator;
/*      */ import java.util.List;
/*      */ import java.util.Map;
/*      */ import java.util.Map.Entry;
/*      */ import java.util.Set;
/*      */ import java.util.SortedMap;
/*      */ import java.util.SortedSet;
/*      */ import java.util.TreeMap;
/*      */ import java.util.TreeSet;
/*      */ import net.spy.memcached.HashAlgorithm;
/*      */ import org.apache.commons.cli.CommandLine;
/*      */ import org.apache.commons.cli.CommandLineParser;
/*      */ import org.apache.commons.cli.Option;
/*      */ import org.apache.commons.cli.Options;
/*      */ import org.apache.commons.cli.ParseException;
/*      */ import org.apache.commons.cli.PosixParser;
/*      */ import org.apache.commons.codec.binary.Base64;
/*      */ import org.apache.commons.httpclient.Header;
/*      */ import org.apache.commons.httpclient.HttpState;
/*      */ import org.apache.commons.httpclient.URI;
/*      */ import org.apache.commons.httpclient.URIException;
/*      */ import org.apache.commons.httpclient.methods.PostMethod;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class ProvUtil
/*      */   implements SoapHttpTransport.HttpDebugListener
/*      */ {
/*      */   private static final String ERR_VIA_SOAP_ONLY = "can only be used with SOAP";
/*      */   private static final String ERR_VIA_LDAP_ONLY = "can only be used with  \"zmprov -l/--ldap\"";
/*      */   private static final String ERR_INVALID_ARG_EV = "arg -e is invalid unless -v is also specified";
/*  150 */   private static final PrintStream console = System.out;
/*  151 */   private static final PrintStream errConsole = System.err;
/*      */   
/*      */   static enum SoapDebugLevel {
/*  154 */     none, 
/*  155 */     normal, 
/*  156 */     high;
/*      */     
/*      */     private SoapDebugLevel() {} }
/*  159 */   private boolean batchMode = false;
/*  160 */   private boolean interactiveMode = false;
/*  161 */   private boolean verboseMode = false;
/*  162 */   private SoapDebugLevel debugLevel = SoapDebugLevel.none;
/*  163 */   private boolean useLdap = LC.zimbra_zmprov_default_to_ldap.booleanValue();
/*  164 */   private boolean useLdapMaster = false;
/*  165 */   private String account = null;
/*  166 */   private String password = null;
/*  167 */   private ZAuthToken authToken = null;
/*  168 */   private String serverHostname = LC.zimbra_zmprov_default_soap_server.value();
/*  169 */   private int serverPort = LC.zimbra_admin_service_port.intValue();
/*      */   
/*      */   private Command command;
/*      */   private Map<String, Command> commandIndex;
/*      */   private Provisioning prov;
/*      */   private BufferedReader cliReader;
/*      */   private boolean outputBinaryToFile;
/*      */   private boolean allowMultiValuedAttrReplacement;
/*      */   private long sendStart;
/*      */   private boolean forceDisplayAttrValue;
/*  179 */   private boolean errorOccursDuringInteraction = false;
/*      */   
/*      */   public void setDebug(SoapDebugLevel value) {
/*  182 */     this.debugLevel = value;
/*      */   }
/*      */   
/*      */   public void setVerbose(boolean value) {
/*  186 */     this.verboseMode = value;
/*      */   }
/*      */   
/*      */   public void setUseLdap(boolean ldap, boolean master) {
/*  190 */     this.useLdap = ldap;
/*  191 */     this.useLdapMaster = master;
/*      */   }
/*      */   
/*      */   public void setAccount(String value) {
/*  195 */     this.account = value;
/*  196 */     this.useLdap = false;
/*      */   }
/*      */   
/*      */   public void setPassword(String value) {
/*  200 */     this.password = value;
/*  201 */     this.useLdap = false;
/*      */   }
/*      */   
/*      */   public void setAuthToken(ZAuthToken value) {
/*  205 */     this.authToken = value;
/*  206 */     this.useLdap = false;
/*      */   }
/*      */   
/*      */   private void setOutputBinaryToFile(boolean value) {
/*  210 */     this.outputBinaryToFile = value;
/*      */   }
/*      */   
/*      */   private void setBatchMode(boolean value) {
/*  214 */     this.batchMode = value;
/*      */   }
/*      */   
/*      */   private void setAllowMultiValuedAttrReplacement(boolean value) {
/*  218 */     this.allowMultiValuedAttrReplacement = value;
/*      */   }
/*      */   
/*      */   private boolean outputBinaryToFile() {
/*  222 */     return this.outputBinaryToFile;
/*      */   }
/*      */   
/*      */   private void setForceDisplayAttrValue(boolean value) {
/*  226 */     this.forceDisplayAttrValue = value;
/*      */   }
/*      */   
/*      */   public void setServer(String value) {
/*  230 */     int i = value.indexOf(":");
/*  231 */     if (i == -1) {
/*  232 */       this.serverHostname = value;
/*      */     } else {
/*  234 */       this.serverHostname = value.substring(0, i);
/*  235 */       this.serverPort = Integer.parseInt(value.substring(i + 1));
/*      */     }
/*  237 */     this.useLdap = false;
/*      */   }
/*      */   
/*      */   public boolean useLdap() {
/*  241 */     return this.useLdap;
/*      */   }
/*      */   
/*      */   private void deprecated() {
/*  245 */     console.println("This command has been deprecated.");
/*  246 */     System.exit(1);
/*      */   }
/*      */   
/*      */   private void usage() {
/*  250 */     usage(null);
/*      */   }
/*      */   
/*      */   private void usage(ProvUtil.Command.Via violatedVia) {
/*  254 */     boolean givenHelp = false;
/*  255 */     if (this.command != null) {
/*  256 */       if (violatedVia == null) {
/*  257 */         console.printf("usage:  %s(%s) %s\n", new Object[] { this.command.getName(), this.command.getAlias(), this.command.getHelp() });
/*  258 */         givenHelp = true;
/*  259 */         CommandHelp extraHelp = this.command.getExtraHelp();
/*  260 */         if (extraHelp != null) {
/*  261 */           extraHelp.printHelp();
/*      */         }
/*      */       }
/*  264 */       else if (violatedVia == ProvUtil.Command.Via.ldap) {
/*  265 */         console.printf("%s %s\n", new Object[] { this.command.getName(), "can only be used with  \"zmprov -l/--ldap\"" });
/*      */       } else {
/*  267 */         console.printf("%s %s\n", new Object[] { this.command.getName(), "can only be used with SOAP" });
/*      */       }
/*      */     }
/*      */     
/*  271 */     if (this.interactiveMode) {
/*  272 */       return;
/*      */     }
/*  274 */     if (givenHelp) {
/*  275 */       console.println("For general help, type : zmprov --help");
/*  276 */       System.exit(1);
/*      */     }
/*  278 */     console.println("");
/*  279 */     console.println("zmprov [args] [cmd] [cmd-args ...]");
/*  280 */     console.println("");
/*  281 */     console.println("  -h/--help                             display usage");
/*  282 */     console.println("  -f/--file                             use file as input stream");
/*  283 */     console.println("  -s/--server   {host}[:{port}]         server hostname and optional port");
/*  284 */     console.println("  -l/--ldap                             provision via LDAP instead of SOAP");
/*  285 */     console.println("  -L/--logpropertyfile                  log4j property file, valid only with -l");
/*  286 */     console.println("  -a/--account  {name}                  account name to auth as");
/*  287 */     console.println("  -p/--password {pass}                  password for account");
/*  288 */     console.println("  -P/--passfile {file}                  read password from file");
/*  289 */     console.println("  -z/--zadmin                           use zimbra admin name/password from localconfig for admin/password");
/*  290 */     console.println("  -y/--authtoken {authtoken}            " + SoapCLI.OPT_AUTHTOKEN.getDescription());
/*  291 */     console.println("  -Y/--authtokenfile {authtoken file}   " + SoapCLI.OPT_AUTHTOKENFILE.getDescription());
/*  292 */     console.println("  -v/--verbose                          verbose mode (dumps full exception stack trace)");
/*  293 */     console.println("  -d/--debug                            debug mode (dumps SOAP messages)");
/*  294 */     console.println("  -m/--master                           use LDAP master (only valid with -l)");
/*  295 */     console.println("  -r/--replace                          allow replacement of safe-guarded multi-valued attributes configured in localconfig key \"zmprov_safeguarded_attrs\"");
/*  296 */     console.println("");
/*  297 */     doHelp(null);
/*  298 */     System.exit(1);
/*      */   }
/*      */   
/*      */   public static enum Category {
/*  302 */     ACCOUNT("help on account-related commands"), 
/*  303 */     CALENDAR("help on calendar resource-related commands"), 
/*  304 */     COMMANDS("help on all commands"), 
/*  305 */     CONFIG("help on config-related commands"), 
/*  306 */     COS("help on COS-related commands"), 
/*  307 */     DOMAIN("help on domain-related commands"), 
/*  308 */     FREEBUSY("help on free/busy-related commands"), 
/*  309 */     LIST("help on distribution list-related commands"), 
/*  310 */     LOG("help on logging commands"), 
/*  311 */     MISC("help on misc commands"), 
/*  312 */     MAILBOX("help on mailbox-related commands"), 
/*  313 */     REVERSEPROXY("help on reverse proxy related commands"), 
/*  314 */     RIGHT("help on right-related commands"), 
/*  315 */     SEARCH("help on search-related commands"), 
/*  316 */     SERVER("help on server-related commands"), 
/*  317 */     ALWAYSONCLUSTER("help on alwaysOnCluster-related commands"), 
/*  318 */     UCSERVICE("help on ucservice-related commands"), 
/*  319 */     SHARE("help on share related commands");
/*      */     
/*      */     private final String description;
/*      */     
/*      */     public String getDescription() {
/*  324 */       return this.description;
/*      */     }
/*      */     
/*      */     private Category(String desc) {
/*  328 */       this.description = desc;
/*      */     }
/*      */     
/*      */     static void help(Category cat) {
/*  332 */       switch (ProvUtil.7.$SwitchMap$com$zimbra$cs$account$ProvUtil$Category[cat.ordinal()]) {
/*      */       case 1: 
/*  334 */         helpCALENDAR();
/*  335 */         break;
/*      */       case 2: 
/*  337 */         helpRIGHT();
/*  338 */         break;
/*      */       case 3: 
/*  340 */         helpLOG();
/*      */       }
/*      */     }
/*      */     
/*      */     static void helpCALENDAR()
/*      */     {
/*  346 */       ProvUtil.console.println("");
/*  347 */       StringBuilder sb = new StringBuilder();
/*  348 */       EntrySearchFilter.Operator[] vals = EntrySearchFilter.Operator.values();
/*  349 */       for (int i = 0; i < vals.length; i++) {
/*  350 */         if (i > 0) {
/*  351 */           sb.append(", ");
/*      */         }
/*  353 */         sb.append(vals[i].toString());
/*      */       }
/*  355 */       ProvUtil.console.println("    op = " + sb.toString());
/*      */     }
/*      */     
/*      */     static void helpRIGHT() {
/*  359 */       helpRIGHTCommon(true);
/*  360 */       helpRIGHTRights(false, true);
/*      */     }
/*      */     
/*      */     static void helpRIGHTCommand(boolean printRights, boolean secretPossible, boolean modifierPossible) {
/*  364 */       helpRIGHTCommon(secretPossible);
/*  365 */       helpRIGHTRights(false, modifierPossible);
/*      */     }
/*      */     
/*      */     static void helpRIGHTRights(boolean printRights, boolean modifierPossible)
/*      */     {
/*  370 */       ProvUtil.console.println();
/*  371 */       if (modifierPossible) {
/*  372 */         ProvUtil.console.println("    {right}: can have the following prefixes:");
/*  373 */         for (RightModifier rm : RightModifier.values()) {
/*  374 */           ProvUtil.console.println("            " + rm.getModifier() + " : " + rm.getDescription());
/*      */         }
/*  376 */         ProvUtil.console.println();
/*      */       }
/*      */       
/*  379 */       if (printRights) {
/*      */         try {
/*  381 */           Map<String, AdminRight> allAdminRights = RightManager.getInstance().getAllAdminRights();
/*      */           
/*  383 */           for (Right r : allAdminRights.values()) {
/*  384 */             if (Right.RightType.combo != r.getRightType()) {
/*  385 */               ProvUtil.console.println("        " + r.getName() + " (" + r.getRightType().toString() + ")");
/*      */             }
/*      */           }
/*      */           
/*  389 */           for (Right r : allAdminRights.values()) {
/*  390 */             if (Right.RightType.combo == r.getRightType()) {
/*  391 */               ProvUtil.console.println("        " + r.getName() + " (" + r.getRightType().toString() + ")");
/*      */             }
/*      */           }
/*      */         } catch (ServiceException e) {
/*  395 */           ProvUtil.console.println("cannot get RightManager instance: " + e.getMessage());
/*      */         }
/*      */       } else {
/*  398 */         ProvUtil.console.println("         for complete list of rights, do \"zmprov gar -c ALL\"");
/*      */       }
/*      */       
/*  401 */       ProvUtil.console.println();
/*      */     }
/*      */     
/*      */     static void helpRIGHTCommon(boolean secretPossible)
/*      */     {
/*  406 */       ProvUtil.console.println();
/*  407 */       StringBuilder tt = new StringBuilder();
/*  408 */       StringBuilder ttNeedsTargetIdentity = new StringBuilder();
/*  409 */       StringBuilder ttNoTargetId = new StringBuilder();
/*  410 */       TargetType[] tts = TargetType.values();
/*  411 */       for (int i = 0; i < tts.length; i++) {
/*  412 */         if (i > 0) {
/*  413 */           tt.append(", ");
/*      */         }
/*  415 */         tt.append(tts[i].getCode());
/*  416 */         if (tts[i].needsTargetIdentity()) {
/*  417 */           ttNeedsTargetIdentity.append(tts[i].getCode() + " ");
/*      */         } else {
/*  419 */           ttNoTargetId.append(tts[i].getCode() + " ");
/*      */         }
/*      */       }
/*  422 */       ProvUtil.console.println("    {target-type} = " + tt.toString());
/*  423 */       ProvUtil.console.println();
/*  424 */       ProvUtil.console.println("    {target-id|target-name} is required if target-type is: " + ttNeedsTargetIdentity);
/*  425 */       ProvUtil.console.println("    {target-id|target-name} should not be specified if target-type is: " + ttNoTargetId);
/*      */       
/*      */ 
/*  428 */       ProvUtil.console.println();
/*  429 */       StringBuilder gt = new StringBuilder();
/*  430 */       StringBuilder gtNeedsGranteeIdentity = new StringBuilder();
/*  431 */       StringBuilder gtNoGranteeId = new StringBuilder();
/*  432 */       StringBuilder gtNeedsSecret = new StringBuilder();
/*  433 */       StringBuilder gtNoSecret = new StringBuilder();
/*  434 */       GranteeType[] gts = GranteeType.values();
/*  435 */       for (int i = 0; i < gts.length; i++) {
/*  436 */         if (i > 0) {
/*  437 */           gt.append(", ");
/*      */         }
/*  439 */         gt.append(gts[i].getCode());
/*  440 */         if (gts[i].needsGranteeIdentity()) {
/*  441 */           gtNeedsGranteeIdentity.append(gts[i].getCode() + " ");
/*      */         } else {
/*  443 */           gtNoGranteeId.append(gts[i].getCode() + " ");
/*      */         }
/*  445 */         if (secretPossible) {
/*  446 */           if (gts[i].allowSecret()) {
/*  447 */             gtNeedsSecret.append(gts[i].getCode() + " ");
/*      */           } else {
/*  449 */             gtNoSecret.append(gts[i].getCode() + " ");
/*      */           }
/*      */         }
/*      */       }
/*  453 */       ProvUtil.console.println("    {grantee-type} = " + gt.toString());
/*  454 */       ProvUtil.console.println();
/*  455 */       ProvUtil.console.println("    {grantee-id|grantee-name} is required if grantee-type is one of: " + gtNeedsGranteeIdentity);
/*      */       
/*  457 */       ProvUtil.console.println("    {grantee-id|grantee-name} should not be specified if grantee-type is one of: " + gtNoGranteeId);
/*      */       
/*  459 */       if (secretPossible) {
/*  460 */         ProvUtil.console.println();
/*  461 */         ProvUtil.console.println("    {secret} is required if grantee-type is one of: " + gtNeedsSecret);
/*  462 */         ProvUtil.console.println("    {secret} should not be specified if grantee-type is one of: " + gtNoSecret);
/*      */       }
/*      */     }
/*      */     
/*      */     static void helpLOG() {
/*  467 */       ProvUtil.console.println("    Log categories:");
/*  468 */       int maxNameLength = 0;
/*  469 */       for (String name : ZimbraLog.CATEGORY_DESCRIPTIONS.keySet()) {
/*  470 */         if (name.length() > maxNameLength) {
/*  471 */           maxNameLength = name.length();
/*      */         }
/*      */       }
/*  474 */       for (String name : ZimbraLog.CATEGORY_DESCRIPTIONS.keySet()) {
/*  475 */         ProvUtil.console.print("        " + name);
/*  476 */         for (int i = 0; i < maxNameLength - name.length(); i++) {
/*  477 */           ProvUtil.console.print(" ");
/*      */         }
/*  479 */         ProvUtil.console.format(" - %s\n", new Object[] { ZimbraLog.CATEGORY_DESCRIPTIONS.get(name) });
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   static abstract interface CommandHelp {
/*      */     public abstract void printHelp();
/*      */   }
/*      */   
/*      */   static class RightCommandHelp implements ProvUtil.CommandHelp {
/*      */     boolean printRights;
/*      */     boolean secretPossible;
/*      */     boolean modifierPossible;
/*      */     
/*      */     RightCommandHelp(boolean printRights, boolean secretPossible, boolean modifierPossible) {
/*  494 */       this.printRights = printRights;
/*  495 */       this.secretPossible = secretPossible;
/*  496 */       this.modifierPossible = modifierPossible;
/*      */     }
/*      */     
/*      */     public void printHelp() {
/*  500 */       ProvUtil.Category.helpRIGHTCommand(this.printRights, this.secretPossible, this.modifierPossible);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   static class ReindexCommandHelp
/*      */     implements ProvUtil.CommandHelp
/*      */   {
/*      */     public void printHelp()
/*      */     {
/*  512 */       ProvUtil.console.println();
/*  513 */       ProvUtil.console.println("Valid types:");
/*  514 */       ProvUtil.console.println("    appointment");
/*      */       
/*      */ 
/*  517 */       ProvUtil.console.println("    contact");
/*  518 */       ProvUtil.console.println("    conversation");
/*  519 */       ProvUtil.console.println("    document");
/*  520 */       ProvUtil.console.println("    message");
/*  521 */       ProvUtil.console.println("    note");
/*      */       
/*  523 */       ProvUtil.console.println("    task");
/*  524 */       ProvUtil.console.println();
/*      */     }
/*      */   }
/*      */   
/*      */   public static enum Command {
/*  529 */     ADD_ACCOUNT_ALIAS("addAccountAlias", "aaa", "{name@domain|id} {alias@domain}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  530 */     ADD_ACCOUNT_LOGGER("addAccountLogger", "aal", "[-s/--server hostname] {name@domain|id} {logging-category} {trace|debug|info|warn|error}", ProvUtil.Category.LOG, 3, 5), 
/*  531 */     ADD_DISTRIBUTION_LIST_ALIAS("addDistributionListAlias", "adla", "{list@domain|id} {alias@domain}", ProvUtil.Category.LIST, 2, 2), 
/*  532 */     ADD_DISTRIBUTION_LIST_MEMBER("addDistributionListMember", "adlm", "{list@domain|id} {member@domain}+", ProvUtil.Category.LIST, 2, Integer.MAX_VALUE), 
/*  533 */     AUTO_COMPLETE_GAL("autoCompleteGal", "acg", "{domain} {name}", ProvUtil.Category.SEARCH, 2, 2), 
/*  534 */     AUTO_PROV_CONTROL("autoProvControl", "apc", "{start|status|stop}", ProvUtil.Category.COMMANDS, 1, 1), 
/*  535 */     CHECK_PASSWORD_STRENGTH("checkPasswordStrength", "cps", "{name@domain|id} {password}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  536 */     CHECK_RIGHT("checkRight", "ckr", "{target-type} [{target-id|target-name}] {grantee-id|grantee-name (note:can only check internal user)} {right}", ProvUtil.Category.RIGHT, 3, 4, null, new ProvUtil.RightCommandHelp(false, false, true)), 
/*      */     
/*  538 */     COPY_COS("copyCos", "cpc", "{src-cos-name|id} {dest-cos-name}", ProvUtil.Category.COS, 2, 2), 
/*  539 */     COUNT_ACCOUNT("countAccount", "cta", "{domain|id}", ProvUtil.Category.DOMAIN, 1, 1), 
/*  540 */     COUNT_OBJECTS("countObjects", "cto", "{" + CountObjectsType.names("|") + "} [-d {domain|id}] [-u {UCService|id}]", ProvUtil.Category.MISC, 1, 4), 
/*  541 */     CREATE_ACCOUNT("createAccount", "ca", "{name@domain} {password} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 2, Integer.MAX_VALUE), 
/*  542 */     CREATE_ALIAS_DOMAIN("createAliasDomain", "cad", "{alias-domain-name} {local-domain-name|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.DOMAIN, 2, Integer.MAX_VALUE), 
/*  543 */     CREATE_ALWAYSONCLUSTER("createAlwaysOnCluster", "caoc", "{name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ALWAYSONCLUSTER, 1, Integer.MAX_VALUE), 
/*  544 */     CREATE_BULK_ACCOUNTS("createBulkAccounts", "cabulk", "{domain} {namemask} {number of accounts to create}", ProvUtil.Category.MISC, 3, 3), 
/*  545 */     CREATE_CALENDAR_RESOURCE("createCalendarResource", "ccr", "{name@domain} {password} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.CALENDAR, 2, Integer.MAX_VALUE), 
/*  546 */     CREATE_COS("createCos", "cc", "{name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.COS, 1, Integer.MAX_VALUE), 
/*  547 */     CREATE_DATA_SOURCE("createDataSource", "cds", "{name@domain} {ds-type} {ds-name} zimbraDataSourceEnabled {TRUE|FALSE} zimbraDataSourceFolderId {folder-id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 3, Integer.MAX_VALUE), 
/*  548 */     CREATE_DISTRIBUTION_LIST("createDistributionList", "cdl", "{list@domain}", ProvUtil.Category.LIST, 1, Integer.MAX_VALUE), 
/*  549 */     CREATE_DYNAMIC_DISTRIBUTION_LIST("createDynamicDistributionList", "cddl", "{list@domain}", ProvUtil.Category.LIST, 1, Integer.MAX_VALUE), 
/*  550 */     CREATE_DISTRIBUTION_LISTS_BULK("createDistributionListsBulk", "cdlbulk"), 
/*  551 */     CREATE_DOMAIN("createDomain", "cd", "{domain} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.DOMAIN, 1, Integer.MAX_VALUE), 
/*  552 */     CREATE_SERVER("createServer", "cs", "{name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.SERVER, 1, Integer.MAX_VALUE), 
/*  553 */     CREATE_UC_SERVICE("createUCService", "cucs", "{name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.UCSERVICE, 1, Integer.MAX_VALUE), 
/*  554 */     CREATE_IDENTITY("createIdentity", "cid", "{name@domain} {identity-name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 2, Integer.MAX_VALUE), 
/*  555 */     CREATE_SIGNATURE("createSignature", "csig", "{name@domain} {signature-name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 2, Integer.MAX_VALUE), 
/*  556 */     CREATE_XMPP_COMPONENT("createXMPPComponent", "cxc", "{short-name} {domain}  {server} {classname} {category} {type} [attr value1 [attr2 value2...]]", ProvUtil.Category.CONFIG, 6, Integer.MAX_VALUE), 
/*  557 */     DELETE_ACCOUNT("deleteAccount", "da", "{name@domain|id}", ProvUtil.Category.ACCOUNT, 1, 1), 
/*  558 */     DELETE_ALWAYSONCLUSTER("deleteAlwaysOnCluster", "daoc", "{name|id}", ProvUtil.Category.ALWAYSONCLUSTER, 1, 1), 
/*  559 */     DELETE_CALENDAR_RESOURCE("deleteCalendarResource", "dcr", "{name@domain|id}", ProvUtil.Category.CALENDAR, 1, 1), 
/*  560 */     DELETE_COS("deleteCos", "dc", "{name|id}", ProvUtil.Category.COS, 1, 1), 
/*  561 */     DELETE_DATA_SOURCE("deleteDataSource", "dds", "{name@domain|id} {ds-name|ds-id}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  562 */     DELETE_DISTRIBUTION_LIST("deleteDistributionList", "ddl", "{list@domain|id}", ProvUtil.Category.LIST, 1, 1), 
/*  563 */     DELETE_DOMAIN("deleteDomain", "dd", "{domain|id}", ProvUtil.Category.DOMAIN, 1, 1), 
/*  564 */     DELETE_IDENTITY("deleteIdentity", "did", "{name@domain|id} {identity-name}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  565 */     DELETE_SIGNATURE("deleteSignature", "dsig", "{name@domain|id} {signature-name}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  566 */     DELETE_SERVER("deleteServer", "ds", "{name|id}", ProvUtil.Category.SERVER, 1, 1), 
/*  567 */     DELETE_UC_SERVICE("deleteUCService", "ducs", "{name|id}", ProvUtil.Category.UCSERVICE, 1, 1), 
/*  568 */     DELETE_XMPP_COMPONENT("deleteXMPPComponent", "dxc", "{xmpp-component-name}", ProvUtil.Category.CONFIG, 1, 1), 
/*  569 */     DESCRIBE("describe", "desc", "[[-v] [-ni] [{entry-type}]] | [-a {attribute-name}]", ProvUtil.Category.MISC, 0, Integer.MAX_VALUE, null, null, true), 
/*  570 */     EXIT("exit", "quit", "", ProvUtil.Category.MISC, 0, 0), 
/*  571 */     FLUSH_CACHE("flushCache", "fc", "[-a] {" + CacheEntryType.names() + "|<extension-cache-type>} [name1|id1 [name2|id2...]]", ProvUtil.Category.MISC, 1, Integer.MAX_VALUE), 
/*  572 */     GENERATE_DOMAIN_PRE_AUTH("generateDomainPreAuth", "gdpa", "{domain|id} {name|id|foreignPrincipal} {by} {timestamp|0} {expires|0}", ProvUtil.Category.MISC, 5, 6), 
/*  573 */     GENERATE_DOMAIN_PRE_AUTH_KEY("generateDomainPreAuthKey", "gdpak", "[-f] {domain|id}", ProvUtil.Category.MISC, 1, 2), 
/*  574 */     GET_ACCOUNT("getAccount", "ga", "[-e] {name@domain|id} [attr1 [attr2...]]", ProvUtil.Category.ACCOUNT, 1, Integer.MAX_VALUE), 
/*  575 */     GET_ALWAYSONCLUSTER("getAlwaysOnCluster", "gaoc", "{name|id} [attr1 [attr2...]]", ProvUtil.Category.ALWAYSONCLUSTER, 1, Integer.MAX_VALUE), 
/*  576 */     GET_DATA_SOURCES("getDataSources", "gds", "{name@domain|id} [arg1 [arg2...]]", ProvUtil.Category.ACCOUNT, 1, Integer.MAX_VALUE), 
/*  577 */     GET_IDENTITIES("getIdentities", "gid", "{name@domain|id} [arg1 [arg...]]", ProvUtil.Category.ACCOUNT, 1, Integer.MAX_VALUE), 
/*  578 */     GET_SIGNATURES("getSignatures", "gsig", "{name@domain|id} [arg1 [arg...]]", ProvUtil.Category.ACCOUNT, 1, Integer.MAX_VALUE), 
/*  579 */     GET_ACCOUNT_MEMBERSHIP("getAccountMembership", "gam", "{name@domain|id}", ProvUtil.Category.ACCOUNT, 1, 2), 
/*  580 */     GET_ALL_ACCOUNTS("getAllAccounts", "gaa", "[-v] [-e] [-s server] [{domain}]", ProvUtil.Category.ACCOUNT, 0, 5, Via.ldap), 
/*  581 */     GET_ACCOUNT_LOGGERS("getAccountLoggers", "gal", "[-s/--server hostname] {name@domain|id}", ProvUtil.Category.LOG, 1, 3), 
/*  582 */     GET_ALL_ACTIVE_SERVERS("getAllActiveServers", "gaas", "[-v]", ProvUtil.Category.SERVER, 0, 1), 
/*  583 */     GET_ALL_ACCOUNT_LOGGERS("getAllAccountLoggers", "gaal", "[-s/--server hostname]", ProvUtil.Category.LOG, 0, 2), 
/*  584 */     GET_ALL_ADMIN_ACCOUNTS("getAllAdminAccounts", "gaaa", "[-v] [-e] [attr1 [attr2...]]", ProvUtil.Category.ACCOUNT, 0, Integer.MAX_VALUE), 
/*  585 */     GET_ALL_ALWAYSONCLUSTERS("getAllAlwaysOnClusters", "gaaoc", "[-v]", ProvUtil.Category.ALWAYSONCLUSTER, 0, 1), 
/*  586 */     GET_ALL_CALENDAR_RESOURCES("getAllCalendarResources", "gacr", "[-v] [-e] [-s server] [{domain}]", ProvUtil.Category.CALENDAR, 0, 5), 
/*  587 */     GET_ALL_CONFIG("getAllConfig", "gacf", "[attr1 [attr2...]]", ProvUtil.Category.CONFIG, 0, Integer.MAX_VALUE), 
/*  588 */     GET_ALL_COS("getAllCos", "gac", "[-v]", ProvUtil.Category.COS, 0, 1), 
/*  589 */     GET_ALL_DISTRIBUTION_LISTS("getAllDistributionLists", "gadl", "[-v] [{domain}]", ProvUtil.Category.LIST, 0, 2), 
/*  590 */     GET_ALL_DOMAINS("getAllDomains", "gad", "[-v] [-e] [attr1 [attr2...]]", ProvUtil.Category.DOMAIN, 0, Integer.MAX_VALUE), 
/*  591 */     GET_ALL_EFFECTIVE_RIGHTS("getAllEffectiveRights", "gaer", "{grantee-type} {grantee-id|grantee-name} [expandSetAttrs] [expandGetAttrs]", ProvUtil.Category.RIGHT, 2, 4), 
/*  592 */     GET_ALL_FREEBUSY_PROVIDERS("getAllFbp", "gafbp", "[-v]", ProvUtil.Category.FREEBUSY, 0, 1), 
/*  593 */     GET_ALL_RIGHTS("getAllRights", "gar", "[-v] [-t {target-type}] [-c " + RightClass.allValuesInString("|") + "]", ProvUtil.Category.RIGHT, 0, 5), 
/*  594 */     GET_ALL_SERVERS("getAllServers", "gas", "[-v] [-e] [service]", ProvUtil.Category.SERVER, 0, 3), 
/*  595 */     GET_ALL_UC_SERVICES("getAllUCServices", "gaucs", "[-v]", ProvUtil.Category.UCSERVICE, 0, 3), 
/*  596 */     GET_ALL_XMPP_COMPONENTS("getAllXMPPComponents", "gaxcs", "", ProvUtil.Category.CONFIG, 0, 0), 
/*  597 */     GET_AUTH_TOKEN_INFO("getAuthTokenInfo", "gati", "{auth-token}", ProvUtil.Category.MISC, 1, 1), 
/*  598 */     GET_CALENDAR_RESOURCE("getCalendarResource", "gcr", "{name@domain|id} [attr1 [attr2...]]", ProvUtil.Category.CALENDAR, 1, Integer.MAX_VALUE), 
/*  599 */     GET_CONFIG("getConfig", "gcf", "{name}", ProvUtil.Category.CONFIG, 1, 1), 
/*  600 */     GET_COS("getCos", "gc", "{name|id} [attr1 [attr2...]]", ProvUtil.Category.COS, 1, Integer.MAX_VALUE), 
/*  601 */     GET_DISTRIBUTION_LIST("getDistributionList", "gdl", "{list@domain|id} [attr1 [attr2...]]", ProvUtil.Category.LIST, 1, Integer.MAX_VALUE), 
/*  602 */     GET_DISTRIBUTION_LIST_MEMBERSHIP("getDistributionListMembership", "gdlm", "{name@domain|id}", ProvUtil.Category.LIST, 1, 1), 
/*  603 */     GET_DOMAIN("getDomain", "gd", "[-e] {domain|id} [attr1 [attr2...]]", ProvUtil.Category.DOMAIN, 1, Integer.MAX_VALUE), 
/*  604 */     GET_DOMAIN_INFO("getDomainInfo", "gdi", "name|id|virtualHostname {value} [attr1 [attr2...]]", ProvUtil.Category.DOMAIN, 2, Integer.MAX_VALUE), 
/*  605 */     GET_CONFIG_SMIME_CONFIG("getConfigSMIMEConfig", "gcsc", "[configName]", ProvUtil.Category.DOMAIN, 0, 1), 
/*  606 */     GET_DOMAIN_SMIME_CONFIG("getDomainSMIMEConfig", "gdsc", "name|id [configName]", ProvUtil.Category.DOMAIN, 1, 2), 
/*  607 */     GET_EFFECTIVE_RIGHTS("getEffectiveRights", "ger", "{target-type} [{target-id|target-name}] {grantee-id|grantee-name} [expandSetAttrs] [expandGetAttrs]", ProvUtil.Category.RIGHT, 1, 5, null, new ProvUtil.RightCommandHelp(false, false, false)), 
/*      */     
/*      */ 
/*      */ 
/*  611 */     GET_CREATE_OBJECT_ATTRS("getCreateObjectAttrs", "gcoa", "{target-type} {domain-id|domain-name} {cos-id|cos-name} {grantee-id|grantee-name}", ProvUtil.Category.RIGHT, 3, 4), 
/*      */     
/*  613 */     GET_FREEBUSY_QUEUE_INFO("getFreebusyQueueInfo", "gfbqi", "[{provider-name}]", ProvUtil.Category.FREEBUSY, 0, 1), 
/*  614 */     GET_GRANTS("getGrants", "gg", "[-t {target-type} [{target-id|target-name}]] [-g {grantee-type} {grantee-id|grantee-name} [{0|1 (whether to include grants granted to groups the grantee belongs)}]]", ProvUtil.Category.RIGHT, 2, 7, null, new ProvUtil.RightCommandHelp(false, false, false)), 
/*      */     
/*  616 */     GET_MAILBOX_INFO("getMailboxInfo", "gmi", "{account}", ProvUtil.Category.MAILBOX, 1, 1), 
/*  617 */     GET_QUOTA_USAGE("getQuotaUsage", "gqu", "{server}", ProvUtil.Category.MAILBOX, 1, 1), 
/*  618 */     GET_RIGHT("getRight", "gr", "{right} [-e] (whether to expand combo rights recursively)", ProvUtil.Category.RIGHT, 1, 2), 
/*  619 */     GET_RIGHTS_DOC("getRightsDoc", "grd", "[java packages]", ProvUtil.Category.RIGHT, 0, Integer.MAX_VALUE), 
/*  620 */     GET_SERVER("getServer", "gs", "[-e] {name|id} [attr1 [attr2...]]", ProvUtil.Category.SERVER, 1, Integer.MAX_VALUE), 
/*  621 */     GET_UC_SERVICES("getUCService", "gucs", "[-e] {name|id} [attr1 [attr2...]]", ProvUtil.Category.UCSERVICE, 1, Integer.MAX_VALUE), 
/*  622 */     GET_SHARE_INFO("getShareInfo", "gsi", "{owner-name|owner-id}", ProvUtil.Category.SHARE, 1, 1), 
/*  623 */     GET_SPNEGO_DOMAIN("getSpnegoDomain", "gsd", "", ProvUtil.Category.MISC, 0, 0), 
/*  624 */     GET_XMPP_COMPONENT("getXMPPComponent", "gxc", "{name|id} [attr1 [attr2...]]", ProvUtil.Category.CONFIG, 1, Integer.MAX_VALUE), 
/*  625 */     GRANT_RIGHT("grantRight", "grr", "{target-type} [{target-id|target-name}] {grantee-type} [{grantee-id|grantee-name} [secret]] {right}", ProvUtil.Category.RIGHT, 3, 6, null, new ProvUtil.RightCommandHelp(false, true, true)), 
/*      */     
/*  627 */     HELP("help", "?", "commands", ProvUtil.Category.MISC, 0, 1), 
/*  628 */     LDAP(".ldap", ".l"), 
/*  629 */     MODIFY_ACCOUNT("modifyAccount", "ma", "{name@domain|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 3, Integer.MAX_VALUE), 
/*  630 */     MODIFY_ALWAYSONCLUSTER("modifyAlwaysOnCluster", "maoc", "{name|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ALWAYSONCLUSTER, 3, Integer.MAX_VALUE), 
/*  631 */     MODIFY_CALENDAR_RESOURCE("modifyCalendarResource", "mcr", "{name@domain|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.CALENDAR, 3, Integer.MAX_VALUE), 
/*  632 */     MODIFY_CONFIG("modifyConfig", "mcf", "attr1 value1 [attr2 value2...]", ProvUtil.Category.CONFIG, 2, Integer.MAX_VALUE), 
/*  633 */     MODIFY_COS("modifyCos", "mc", "{name|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.COS, 3, Integer.MAX_VALUE), 
/*  634 */     MODIFY_DATA_SOURCE("modifyDataSource", "mds", "{name@domain|id} {ds-name|ds-id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 4, Integer.MAX_VALUE), 
/*  635 */     MODIFY_DISTRIBUTION_LIST("modifyDistributionList", "mdl", "{list@domain|id} attr1 value1 [attr2 value2...]", ProvUtil.Category.LIST, 3, Integer.MAX_VALUE), 
/*  636 */     MODIFY_DOMAIN("modifyDomain", "md", "{domain|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.DOMAIN, 3, Integer.MAX_VALUE), 
/*  637 */     MODIFY_CONFIG_SMIME_CONFIG("modifyConfigSMIMEConfig", "mcsc", "configName [attr2 value2...]]", ProvUtil.Category.DOMAIN, 1, Integer.MAX_VALUE), 
/*  638 */     MODIFY_DOMAIN_SMIME_CONFIG("modifyDomainSMIMEConfig", "mdsc", "name|id configName [attr2 value2...]]", ProvUtil.Category.DOMAIN, 2, Integer.MAX_VALUE), 
/*  639 */     MODIFY_IDENTITY("modifyIdentity", "mid", "{name@domain|id} {identity-name} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 4, Integer.MAX_VALUE), 
/*  640 */     MODIFY_SIGNATURE("modifySignature", "msig", "{name@domain|id} {signature-name|signature-id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.ACCOUNT, 4, Integer.MAX_VALUE), 
/*  641 */     MODIFY_SERVER("modifyServer", "ms", "{name|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.SERVER, 3, Integer.MAX_VALUE), 
/*  642 */     MODIFY_UC_SERVICE("modifyUCService", "mucs", "{name|id} [attr1 value1 [attr2 value2...]]", ProvUtil.Category.UCSERVICE, 3, Integer.MAX_VALUE), 
/*  643 */     MODIFY_XMPP_COMPONENT("modifyXMPPComponent", "mxc", "{name@domain} [attr1 value1 [attr value2...]]", ProvUtil.Category.CONFIG, 3, Integer.MAX_VALUE), 
/*  644 */     PUSH_FREEBUSY("pushFreebusy", "pfb", "[account-id ...]", ProvUtil.Category.FREEBUSY, 1, Integer.MAX_VALUE), 
/*  645 */     PUSH_FREEBUSY_DOMAIN("pushFreebusyDomain", "pfbd", "{domain}", ProvUtil.Category.FREEBUSY, 1, 1), 
/*  646 */     PURGE_ACCOUNT_CALENDAR_CACHE("purgeAccountCalendarCache", "pacc", "{name@domain|id} [...]", ProvUtil.Category.CALENDAR, 1, Integer.MAX_VALUE), 
/*  647 */     PURGE_FREEBUSY_QUEUE("purgeFreebusyQueue", "pfbq", "[{provider-name}]", ProvUtil.Category.FREEBUSY, 0, 1), 
/*  648 */     RECALCULATE_MAILBOX_COUNTS("recalculateMailboxCounts", "rmc", "{name@domain|id}", ProvUtil.Category.MAILBOX, 1, 1), 
/*  649 */     REMOVE_ACCOUNT_ALIAS("removeAccountAlias", "raa", "{name@domain|id} {alias@domain}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  650 */     REMOVE_ACCOUNT_LOGGER("removeAccountLogger", "ral", "[-s/--server hostname] [{name@domain|id}] [{logging-category}]", ProvUtil.Category.LOG, 0, 4), 
/*  651 */     REMOVE_DISTRIBUTION_LIST_ALIAS("removeDistributionListAlias", "rdla", "{list@domain|id} {alias@domain}", ProvUtil.Category.LIST, 2, 2), 
/*  652 */     REMOVE_DISTRIBUTION_LIST_MEMBER("removeDistributionListMember", "rdlm", "{list@domain|id} {member@domain}", ProvUtil.Category.LIST, 2, Integer.MAX_VALUE), 
/*  653 */     REMOVE_CONFIG_SMIME_CONFIG("removeConfigSMIMEConfig", "rcsc", "configName", ProvUtil.Category.DOMAIN, 1, 1), 
/*  654 */     REMOVE_DOMAIN_SMIME_CONFIG("removeDomainSMIMEConfig", "rdsc", "name|id configName", ProvUtil.Category.DOMAIN, 2, 2), 
/*  655 */     RENAME_ACCOUNT("renameAccount", "ra", "{name@domain|id} {newName@domain}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  656 */     RENAME_CALENDAR_RESOURCE("renameCalendarResource", "rcr", "{name@domain|id} {newName@domain}", ProvUtil.Category.CALENDAR, 2, 2), 
/*  657 */     RENAME_COS("renameCos", "rc", "{name|id} {newName}", ProvUtil.Category.COS, 2, 2), 
/*  658 */     RENAME_DISTRIBUTION_LIST("renameDistributionList", "rdl", "{list@domain|id} {newName@domain}", ProvUtil.Category.LIST, 2, 2), 
/*  659 */     RENAME_DOMAIN("renameDomain", "rd", "{domain|id} {newDomain}", ProvUtil.Category.DOMAIN, 2, 2, Via.ldap), 
/*  660 */     RENAME_UCSERVICE("renameUCService", "rucs", "{name|id} {newName}", ProvUtil.Category.UCSERVICE, 2, 2), 
/*  661 */     REINDEX_MAILBOX("reIndexMailbox", "rim", "{name@domain|id} {start|status|cancel} [{types|ids} {type or id} [,type or id...]]", ProvUtil.Category.MAILBOX, 2, Integer.MAX_VALUE, null, new ProvUtil.ReindexCommandHelp()), 
/*  662 */     COMPACT_INBOX_MAILBOX("compactIndexMailbox", "cim", "{name@domain|id} {start|status}", ProvUtil.Category.MAILBOX, 2, Integer.MAX_VALUE), 
/*  663 */     VERIFY_INDEX("verifyIndex", "vi", "{name@domain|id}", ProvUtil.Category.MAILBOX, 1, 1), 
/*  664 */     GET_INDEX_STATS("getIndexStats", "gis", "{name@domain|id}", ProvUtil.Category.MAILBOX, 1, 1), 
/*  665 */     REVOKE_RIGHT("revokeRight", "rvr", "{target-type} [{target-id|target-name}] {grantee-type} [{grantee-id|grantee-name}] {right}", ProvUtil.Category.RIGHT, 3, 5, null, new ProvUtil.RightCommandHelp(false, false, true)), 
/*      */     
/*  667 */     SEARCH_ACCOUNTS("searchAccounts", "sa", "[-v] {ldap-query} [limit {limit}] [offset {offset}] [sortBy {attr}] [sortAscending 0|1*] [domain {domain}]", ProvUtil.Category.SEARCH, 1, Integer.MAX_VALUE), 
/*  668 */     SEARCH_CALENDAR_RESOURCES("searchCalendarResources", "scr", "[-v] domain attr op value [attr op value...]", ProvUtil.Category.SEARCH, 1, Integer.MAX_VALUE, Via.ldap), 
/*  669 */     SEARCH_GAL("searchGal", "sg", "{domain} {name} [limit {limit}] [offset {offset}] [sortBy {attr}]", ProvUtil.Category.SEARCH, 2, Integer.MAX_VALUE), 
/*  670 */     SET_LOCAL_SERVER_ONLINE("setLocalServerOnline", "slso", "", ProvUtil.Category.SERVER, 0, 0), 
/*  671 */     SELECT_MAILBOX("selectMailbox", "sm", "{account-name} [{zmmailbox commands}]", ProvUtil.Category.MAILBOX, 1, Integer.MAX_VALUE), 
/*  672 */     SET_ACCOUNT_COS("setAccountCos", "sac", "{name@domain|id} {cos-name|cos-id}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  673 */     SET_PASSWORD("setPassword", "sp", "{name@domain|id} {password}", ProvUtil.Category.ACCOUNT, 2, 2), 
/*  674 */     SET_SERVER_OFFLINE("setServerOffline", "sso", "{name|id}", ProvUtil.Category.SERVER, 1, 1), 
/*  675 */     GET_ALL_MTA_AUTH_URLS("getAllMtaAuthURLs", "gamau", "", ProvUtil.Category.SERVER, 0, 0), 
/*  676 */     GET_ALL_REVERSE_PROXY_URLS("getAllReverseProxyURLs", "garpu", "", ProvUtil.Category.REVERSEPROXY, 0, 0), 
/*  677 */     GET_ALL_REVERSE_PROXY_BACKENDS("getAllReverseProxyBackends", "garpb", "", ProvUtil.Category.REVERSEPROXY, 0, 0), 
/*  678 */     GET_ALL_REVERSE_PROXY_DOMAINS("getAllReverseProxyDomains", "garpd", "", ProvUtil.Category.REVERSEPROXY, 0, 0, Via.ldap), 
/*  679 */     GET_ALL_MEMCACHED_SERVERS("getAllMemcachedServers", "gamcs", "", ProvUtil.Category.SERVER, 0, 0), 
/*  680 */     RELOAD_MEMCACHED_CLIENT_CONFIG("reloadMemcachedClientConfig", "rmcc", "all | mailbox-server [...]", ProvUtil.Category.MISC, 1, Integer.MAX_VALUE, Via.soap), 
/*  681 */     GET_MEMCACHED_CLIENT_CONFIG("getMemcachedClientConfig", "gmcc", "all | mailbox-server [...]", ProvUtil.Category.MISC, 1, Integer.MAX_VALUE, Via.soap), 
/*  682 */     SOAP(".soap", ".s"), 
/*  683 */     SYNC_GAL("syncGal", "syg", "{domain} [{token}]", ProvUtil.Category.MISC, 1, 2), 
/*  684 */     UPDATE_PRESENCE_SESSION_ID("updatePresenceSessionId", "upsid", "{UC service name or id} {app-username} {app-password}", ProvUtil.Category.MISC, 3, 3, Via.soap), 
/*  685 */     RESET_ALL_LOGGERS("resetAllLoggers", "rlog", "[-s/--server hostname]", ProvUtil.Category.LOG, 0, 2), 
/*  686 */     UNLOCK_MAILBOX("unlockMailbox", "ulm", "{name@domain|id} [hostname (When unlocking a mailbox after a failed move attempt provide the hostname of the server that was the target for the failed move. Otherwise, do not include hostname parameter)]", ProvUtil.Category.MAILBOX, 1, 2, Via.soap);
/*      */     
/*      */ 
/*      */     private String mName;
/*      */     private String mAlias;
/*      */     private String mHelp;
/*      */     private ProvUtil.CommandHelp mExtraHelp;
/*      */     private ProvUtil.Category mCat;
/*  694 */     private int mMinArgLength = 0;
/*  695 */     private int mMaxArgLength = Integer.MAX_VALUE;
/*      */     private Via mVia;
/*  697 */     private boolean mNeedsSchemaExtension = false;
/*      */     
/*      */     public static enum Via {
/*  700 */       soap,  ldap;
/*      */       
/*      */       private Via() {} }
/*  703 */     public String getName() { return this.mName; }
/*  704 */     public String getAlias() { return this.mAlias; }
/*  705 */     public String getHelp() { return this.mHelp; }
/*  706 */     public ProvUtil.CommandHelp getExtraHelp() { return this.mExtraHelp; }
/*  707 */     public ProvUtil.Category getCategory() { return this.mCat; }
/*  708 */     public boolean hasHelp() { return this.mHelp != null; }
/*      */     
/*  710 */     public boolean checkArgsLength(String[] args) { int len = args == null ? 0 : args.length - 1;
/*  711 */       return (len >= this.mMinArgLength) && (len <= this.mMaxArgLength); }
/*      */     
/*  713 */     public Via getVia() { return this.mVia; }
/*      */     
/*  715 */     public boolean needsSchemaExtension() { return (this.mNeedsSchemaExtension) || (this.mCat == ProvUtil.Category.RIGHT); }
/*      */     
/*      */     public boolean isDeprecated()
/*      */     {
/*  719 */       return false;
/*      */     }
/*      */     
/*      */     private Command(String name, String alias) {
/*  723 */       this.mName = name;
/*  724 */       this.mAlias = alias;
/*      */     }
/*      */     
/*      */     private Command(String name, String alias, String help, ProvUtil.Category cat) {
/*  728 */       this.mName = name;
/*  729 */       this.mAlias = alias;
/*  730 */       this.mHelp = help;
/*  731 */       this.mCat = cat;
/*      */     }
/*      */     
/*      */     private Command(String name, String alias, String help, ProvUtil.Category cat, int minArgLength, int maxArgLength) {
/*  735 */       this.mName = name;
/*  736 */       this.mAlias = alias;
/*  737 */       this.mHelp = help;
/*  738 */       this.mCat = cat;
/*  739 */       this.mMinArgLength = minArgLength;
/*  740 */       this.mMaxArgLength = maxArgLength;
/*      */     }
/*      */     
/*      */     private Command(String name, String alias, String help, ProvUtil.Category cat, int minArgLength, int maxArgLength, Via via) {
/*  744 */       this.mName = name;
/*  745 */       this.mAlias = alias;
/*  746 */       this.mHelp = help;
/*  747 */       this.mCat = cat;
/*  748 */       this.mMinArgLength = minArgLength;
/*  749 */       this.mMaxArgLength = maxArgLength;
/*  750 */       this.mVia = via;
/*      */     }
/*      */     
/*      */     private Command(String name, String alias, String help, ProvUtil.Category cat, int minArgLength, int maxArgLength, Via via, ProvUtil.CommandHelp extraHelp)
/*      */     {
/*  755 */       this.mName = name;
/*  756 */       this.mAlias = alias;
/*  757 */       this.mHelp = help;
/*  758 */       this.mCat = cat;
/*  759 */       this.mMinArgLength = minArgLength;
/*  760 */       this.mMaxArgLength = maxArgLength;
/*  761 */       this.mVia = via;
/*  762 */       this.mExtraHelp = extraHelp;
/*      */     }
/*      */     
/*      */     private Command(String name, String alias, String help, ProvUtil.Category cat, int minArgLength, int maxArgLength, Via via, ProvUtil.CommandHelp extraHelp, boolean needsSchemaExtension)
/*      */     {
/*  767 */       this(name, alias, help, cat, minArgLength, maxArgLength, via, extraHelp);
/*  768 */       this.mNeedsSchemaExtension = needsSchemaExtension;
/*      */     }
/*      */   }
/*      */   
/*      */   private void addCommand(Command command) {
/*  773 */     String name = command.getName().toLowerCase();
/*  774 */     if (this.commandIndex.get(name) != null) {
/*  775 */       throw new RuntimeException("duplicate command: " + name);
/*      */     }
/*  777 */     String alias = command.getAlias().toLowerCase();
/*  778 */     if (this.commandIndex.get(alias) != null) {
/*  779 */       throw new RuntimeException("duplicate command: " + alias);
/*      */     }
/*  781 */     this.commandIndex.put(name, command);
/*  782 */     this.commandIndex.put(alias, command);
/*      */   }
/*      */   
/*      */   private void initCommands() {
/*  786 */     this.commandIndex = new HashMap();
/*  787 */     for (Command c : Command.values()) {
/*  788 */       addCommand(c);
/*      */     }
/*      */   }
/*      */   
/*      */   private Command lookupCommand(String command) {
/*  793 */     return (Command)this.commandIndex.get(command.toLowerCase());
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private boolean forceLdapButDontRequireUseLdapOption(Command command)
/*      */   {
/*  804 */     return command == Command.DESCRIBE;
/*      */   }
/*      */   
/*      */   private boolean needProvisioningInstance(Command command) {
/*  808 */     return command != Command.HELP;
/*      */   }
/*      */   
/*      */   private ProvUtil() {
/*  812 */     initCommands();
/*      */   }
/*      */   
/*      */   public void initProvisioning() throws ServiceException {
/*  816 */     if (this.useLdap) {
/*  817 */       if (this.useLdapMaster) {
/*  818 */         LdapClient.masterOnly();
/*      */       }
/*  820 */       this.prov = Provisioning.getInstance();
/*      */     } else {
/*  822 */       SoapProvisioning sp = new SoapProvisioning();
/*  823 */       sp.soapSetURI(LC.zimbra_admin_service_scheme.value() + this.serverHostname + ":" + this.serverPort + "/service/admin/soap/");
/*      */       
/*  825 */       if (this.debugLevel != SoapDebugLevel.none) {
/*  826 */         sp.soapSetHttpTransportDebugListener(this);
/*      */       }
/*  828 */       if ((this.account != null) && (this.password != null)) {
/*  829 */         sp.soapAdminAuthenticate(this.account, this.password);
/*  830 */       } else if (this.authToken != null) {
/*  831 */         sp.soapAdminAuthenticate(this.authToken);
/*      */       } else {
/*  833 */         sp.soapZimbraAdminAuthenticate();
/*      */       }
/*  835 */       this.prov = sp;
/*      */     }
/*      */   }
/*      */   
/*      */   private ProvUtil.Command.Via violateVia(Command cmd) {
/*  840 */     ProvUtil.Command.Via via = cmd.getVia();
/*  841 */     if (via == null) {
/*  842 */       return null;
/*      */     }
/*  844 */     if ((via == ProvUtil.Command.Via.ldap) && (!(this.prov instanceof LdapProv))) {
/*  845 */       return ProvUtil.Command.Via.ldap;
/*      */     }
/*  847 */     if ((via == ProvUtil.Command.Via.soap) && (!(this.prov instanceof SoapProvisioning))) {
/*  848 */       return ProvUtil.Command.Via.soap;
/*      */     }
/*  850 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */   private boolean execute(String[] args)
/*      */     throws ServiceException, ProvUtil.ArgException, IOException
/*      */   {
/*  857 */     this.command = lookupCommand(args[0]);
/*  858 */     if (this.command == null) {
/*  859 */       return false;
/*      */     }
/*  861 */     ProvUtil.Command.Via violatedVia = violateVia(this.command);
/*  862 */     if (violatedVia != null) {
/*  863 */       usage(violatedVia);
/*  864 */       return true;
/*      */     }
/*  866 */     if (!this.command.checkArgsLength(args)) {
/*  867 */       usage();
/*  868 */       return true;
/*      */     }
/*  870 */     if (this.command.needsSchemaExtension())
/*  871 */       loadLdapSchemaExtensionAttrs();
/*      */     AccountLoggerOptions alo;
/*  873 */     Account account; String[] members; switch (this.command) {
/*      */     case ADD_ACCOUNT_ALIAS: 
/*  875 */       this.prov.addAlias(lookupAccount(args[1]), args[2]);
/*  876 */       break;
/*      */     case ADD_ACCOUNT_LOGGER: 
/*  878 */       alo = parseAccountLoggerOptions(args);
/*  879 */       if (!this.command.checkArgsLength(alo.args)) {
/*  880 */         usage();
/*  881 */         return true;
/*      */       }
/*  883 */       doAddAccountLogger(alo);
/*  884 */       break;
/*      */     case AUTO_COMPLETE_GAL: 
/*  886 */       doAutoCompleteGal(args);
/*  887 */       break;
/*      */     case AUTO_PROV_CONTROL: 
/*  889 */       this.prov.autoProvControl(args[1]);
/*  890 */       break;
/*      */     case COPY_COS: 
/*  892 */       console.println(this.prov.copyCos(lookupCos(args[1]).getId(), args[2]).getId());
/*  893 */       break;
/*      */     case COUNT_ACCOUNT: 
/*  895 */       doCountAccount(args);
/*  896 */       break;
/*      */     case COUNT_OBJECTS: 
/*  898 */       doCountObjects(args);
/*  899 */       break;
/*      */     case CREATE_ACCOUNT: 
/*  901 */       console.println(this.prov.createAccount(args[1], args[2].equals("") ? null : args[2], getMapAndCheck(args, 3, true)).getId());
/*  902 */       break;
/*      */     case CREATE_ALIAS_DOMAIN: 
/*  904 */       console.println(doCreateAliasDomain(args[1], args[2], getMapAndCheck(args, 3, true)).getId());
/*  905 */       break;
/*      */     case CREATE_ALWAYSONCLUSTER: 
/*  907 */       console.println(this.prov.createAlwaysOnCluster(args[1], getMapAndCheck(args, 2, true)).getId());
/*  908 */       break;
/*      */     case CREATE_COS: 
/*  910 */       console.println(this.prov.createCos(args[1], getMapAndCheck(args, 2, true)).getId());
/*  911 */       break;
/*      */     case CREATE_DOMAIN: 
/*  913 */       console.println(this.prov.createDomain(args[1], getMapAndCheck(args, 2, true)).getId());
/*  914 */       break;
/*      */     case CREATE_IDENTITY: 
/*  916 */       this.prov.createIdentity(lookupAccount(args[1]), args[2], getMapAndCheck(args, 3, true));
/*  917 */       break;
/*      */     case CREATE_SIGNATURE: 
/*  919 */       console.println(this.prov.createSignature(lookupAccount(args[1]), args[2], getMapAndCheck(args, 3, true)).getId());
/*  920 */       break;
/*      */     case CREATE_DATA_SOURCE: 
/*  922 */       console.println(this.prov.createDataSource(lookupAccount(args[1]), DataSourceType.fromString(args[2]), args[3], getMapAndCheck(args, 4, true)).getId());
/*  923 */       break;
/*      */     case CREATE_SERVER: 
/*  925 */       console.println(this.prov.createServer(args[1], getMapAndCheck(args, 2, true)).getId());
/*  926 */       break;
/*      */     case CREATE_UC_SERVICE: 
/*  928 */       console.println(this.prov.createUCService(args[1], getMapAndCheck(args, 2, true)).getId());
/*  929 */       break;
/*      */     case CREATE_XMPP_COMPONENT: 
/*  931 */       doCreateXMPPComponent(args);
/*  932 */       break;
/*      */     case DESCRIBE: 
/*  934 */       doDescribe(args);
/*  935 */       break;
/*      */     case EXIT: 
/*  937 */       System.exit(this.errorOccursDuringInteraction ? 2 : 0);
/*  938 */       break;
/*      */     case FLUSH_CACHE: 
/*  940 */       doFlushCache(args);
/*  941 */       break;
/*      */     case GENERATE_DOMAIN_PRE_AUTH_KEY: 
/*  943 */       doGenerateDomainPreAuthKey(args);
/*  944 */       break;
/*      */     case GENERATE_DOMAIN_PRE_AUTH: 
/*  946 */       doGenerateDomainPreAuth(args);
/*  947 */       break;
/*      */     case GET_ACCOUNT: 
/*  949 */       doGetAccount(args);
/*  950 */       break;
/*      */     case GET_ACCOUNT_MEMBERSHIP: 
/*  952 */       doGetAccountMembership(args);
/*  953 */       break;
/*      */     case GET_ALWAYSONCLUSTER: 
/*  955 */       doGetAlwaysOnCluster(args);
/*  956 */       break;
/*      */     case GET_IDENTITIES: 
/*  958 */       doGetAccountIdentities(args);
/*  959 */       break;
/*      */     case GET_SIGNATURES: 
/*  961 */       doGetAccountSignatures(args);
/*  962 */       break;
/*      */     case GET_DATA_SOURCES: 
/*  964 */       doGetAccountDataSources(args);
/*  965 */       break;
/*      */     case GET_ACCOUNT_LOGGERS: 
/*  967 */       alo = parseAccountLoggerOptions(args);
/*  968 */       if (!this.command.checkArgsLength(alo.args)) {
/*  969 */         usage();
/*  970 */         return true;
/*      */       }
/*  972 */       doGetAccountLoggers(alo);
/*  973 */       break;
/*      */     case GET_ALL_ACCOUNT_LOGGERS: 
/*  975 */       alo = parseAccountLoggerOptions(args);
/*  976 */       if (!this.command.checkArgsLength(alo.args)) {
/*  977 */         usage();
/*  978 */         return true;
/*      */       }
/*  980 */       doGetAllAccountLoggers(alo);
/*  981 */       break;
/*      */     case GET_ALL_ACCOUNTS: 
/*  983 */       doGetAllAccounts(args);
/*  984 */       break;
/*      */     case GET_ALL_ACTIVE_SERVERS: 
/*  986 */       doGetAllActiveServers(args);
/*  987 */       break;
/*      */     case GET_ALL_ADMIN_ACCOUNTS: 
/*  989 */       doGetAllAdminAccounts(args);
/*  990 */       break;
/*      */     case GET_ALL_ALWAYSONCLUSTERS: 
/*  992 */       doGetAllAlwaysOnClusters(args);
/*  993 */       break;
/*      */     case GET_ALL_CONFIG: 
/*  995 */       dumpAttrs(this.prov.getConfig().getAttrs(), getArgNameSet(args, 1));
/*  996 */       break;
/*      */     case GET_ALL_COS: 
/*  998 */       doGetAllCos(args);
/*  999 */       break;
/*      */     case GET_ALL_DOMAINS: 
/* 1001 */       doGetAllDomains(args);
/* 1002 */       break;
/*      */     case GET_ALL_FREEBUSY_PROVIDERS: 
/* 1004 */       doGetAllFreeBusyProviders();
/* 1005 */       break;
/*      */     case GET_ALL_RIGHTS: 
/* 1007 */       doGetAllRights(args);
/* 1008 */       break;
/*      */     case GET_ALL_SERVERS: 
/* 1010 */       doGetAllServers(args);
/* 1011 */       break;
/*      */     case GET_ALL_UC_SERVICES: 
/* 1013 */       doGetAllUCServices(args);
/* 1014 */       break;
/*      */     case GET_CONFIG: 
/* 1016 */       doGetConfig(args);
/* 1017 */       break;
/*      */     case GET_COS: 
/* 1019 */       dumpCos(lookupCos(args[1]), getArgNameSet(args, 2));
/* 1020 */       break;
/*      */     case GET_DISTRIBUTION_LIST_MEMBERSHIP: 
/* 1022 */       doGetDistributionListMembership(lookupGroup(args[1]));
/* 1023 */       break;
/*      */     case GET_DOMAIN: 
/* 1025 */       doGetDomain(args);
/* 1026 */       break;
/*      */     case GET_DOMAIN_INFO: 
/* 1028 */       doGetDomainInfo(args);
/* 1029 */       break;
/*      */     case GET_CONFIG_SMIME_CONFIG: 
/* 1031 */       doGetConfigSMIMEConfig(args);
/* 1032 */       break;
/*      */     case GET_DOMAIN_SMIME_CONFIG: 
/* 1034 */       doGetDomainSMIMEConfig(args);
/* 1035 */       break;
/*      */     case GET_FREEBUSY_QUEUE_INFO: 
/* 1037 */       doGetFreeBusyQueueInfo(args);
/* 1038 */       break;
/*      */     case GET_RIGHT: 
/* 1040 */       doGetRight(args);
/* 1041 */       break;
/*      */     case GET_RIGHTS_DOC: 
/* 1043 */       doGetRightsDoc(args);
/* 1044 */       break;
/*      */     case GET_SERVER: 
/* 1046 */       doGetServer(args);
/* 1047 */       break;
/*      */     case GET_UC_SERVICES: 
/* 1049 */       dumpUCService(lookupUCService(args[1]), getArgNameSet(args, 2));
/* 1050 */       break;
/*      */     case GET_XMPP_COMPONENT: 
/* 1052 */       doGetXMPPComponent(args);
/* 1053 */       break;
/*      */     case CHECK_RIGHT: 
/* 1055 */       doCheckRight(args);
/* 1056 */       break;
/*      */     case GET_ALL_EFFECTIVE_RIGHTS: 
/* 1058 */       doGetAllEffectiveRights(args);
/* 1059 */       break;
/*      */     case GET_EFFECTIVE_RIGHTS: 
/* 1061 */       doGetEffectiveRights(args);
/* 1062 */       break;
/*      */     case GET_CREATE_OBJECT_ATTRS: 
/* 1064 */       doGetCreateObjectAttrs(args);
/* 1065 */       break;
/*      */     case GET_GRANTS: 
/* 1067 */       doGetGrants(args);
/* 1068 */       break;
/*      */     case GRANT_RIGHT: 
/* 1070 */       doGrantRight(args);
/* 1071 */       break;
/*      */     case REVOKE_RIGHT: 
/* 1073 */       doRevokeRight(args);
/* 1074 */       break;
/*      */     case HELP: 
/* 1076 */       doHelp(args);
/* 1077 */       break;
/*      */     case MODIFY_ACCOUNT: 
/* 1079 */       this.prov.modifyAttrs(lookupAccount(args[1]), getMapAndCheck(args, 2, false), true);
/* 1080 */       break;
/*      */     case MODIFY_ALWAYSONCLUSTER: 
/* 1082 */       this.prov.modifyAttrs(lookupAlwaysOnCluster(args[1]), getMapAndCheck(args, 2, false), true);
/* 1083 */       break;
/*      */     case MODIFY_DATA_SOURCE: 
/* 1085 */       account = lookupAccount(args[1]);
/* 1086 */       this.prov.modifyDataSource(account, lookupDataSourceId(account, args[2]), getMapAndCheck(args, 3, false));
/* 1087 */       break;
/*      */     case MODIFY_IDENTITY: 
/* 1089 */       account = lookupAccount(args[1]);
/* 1090 */       this.prov.modifyIdentity(account, args[2], getMapAndCheck(args, 3, false));
/* 1091 */       break;
/*      */     case MODIFY_SIGNATURE: 
/* 1093 */       account = lookupAccount(args[1]);
/* 1094 */       this.prov.modifySignature(account, lookupSignatureId(account, args[2]), getMapAndCheck(args, 3, false));
/* 1095 */       break;
/*      */     case MODIFY_COS: 
/* 1097 */       this.prov.modifyAttrs(lookupCos(args[1]), getMapAndCheck(args, 2, false), true);
/* 1098 */       break;
/*      */     case MODIFY_CONFIG: 
/* 1100 */       this.prov.modifyAttrs(this.prov.getConfig(), getMapAndCheck(args, 1, false), true);
/* 1101 */       break;
/*      */     case MODIFY_DOMAIN: 
/* 1103 */       this.prov.modifyAttrs(lookupDomain(args[1]), getMapAndCheck(args, 2, false), true);
/* 1104 */       break;
/*      */     case MODIFY_CONFIG_SMIME_CONFIG: 
/* 1106 */       doModifyConfigSMIMEConfig(args);
/* 1107 */       break;
/*      */     case MODIFY_DOMAIN_SMIME_CONFIG: 
/* 1109 */       doModifyDomainSMIMEConfig(args);
/* 1110 */       break;
/*      */     case MODIFY_SERVER: 
/* 1112 */       this.prov.modifyAttrs(lookupServer(args[1]), getMapAndCheck(args, 2, false), true);
/* 1113 */       break;
/*      */     case MODIFY_UC_SERVICE: 
/* 1115 */       this.prov.modifyAttrs(lookupUCService(args[1]), getMapAndCheck(args, 2, false), true);
/* 1116 */       break;
/*      */     case DELETE_ACCOUNT: 
/* 1118 */       doDeleteAccount(args);
/* 1119 */       break;
/*      */     case DELETE_ALWAYSONCLUSTER: 
/* 1121 */       this.prov.deleteAlwaysOnCluster(lookupAlwaysOnCluster(args[1]).getId());
/* 1122 */       break;
/*      */     case DELETE_COS: 
/* 1124 */       this.prov.deleteCos(lookupCos(args[1]).getId());
/* 1125 */       break;
/*      */     case DELETE_DOMAIN: 
/* 1127 */       this.prov.deleteDomain(lookupDomain(args[1]).getId());
/* 1128 */       break;
/*      */     case DELETE_IDENTITY: 
/* 1130 */       this.prov.deleteIdentity(lookupAccount(args[1]), args[2]);
/* 1131 */       break;
/*      */     case DELETE_SIGNATURE: 
/* 1133 */       account = lookupAccount(args[1]);
/* 1134 */       this.prov.deleteSignature(account, lookupSignatureId(account, args[2]));
/* 1135 */       break;
/*      */     case DELETE_DATA_SOURCE: 
/* 1137 */       account = lookupAccount(args[1]);
/* 1138 */       this.prov.deleteDataSource(account, lookupDataSourceId(account, args[2]));
/* 1139 */       break;
/*      */     case DELETE_SERVER: 
/* 1141 */       this.prov.deleteServer(lookupServer(args[1]).getId());
/* 1142 */       break;
/*      */     case DELETE_UC_SERVICE: 
/* 1144 */       this.prov.deleteUCService(lookupUCService(args[1]).getId());
/* 1145 */       break;
/*      */     case DELETE_XMPP_COMPONENT: 
/* 1147 */       this.prov.deleteXMPPComponent(lookupXMPPComponent(args[1]));
/* 1148 */       break;
/*      */     case PUSH_FREEBUSY: 
/* 1150 */       doPushFreeBusy(args);
/* 1151 */       break;
/*      */     case PUSH_FREEBUSY_DOMAIN: 
/* 1153 */       doPushFreeBusyForDomain(args);
/* 1154 */       break;
/*      */     case PURGE_FREEBUSY_QUEUE: 
/* 1156 */       doPurgeFreeBusyQueue(args);
/* 1157 */       break;
/*      */     case PURGE_ACCOUNT_CALENDAR_CACHE: 
/* 1159 */       doPurgeAccountCalendarCache(args);
/* 1160 */       break;
/*      */     case REMOVE_ACCOUNT_ALIAS: 
/* 1162 */       Account acct = lookupAccount(args[1], false);
/* 1163 */       this.prov.removeAlias(acct, args[2]);
/*      */       
/*      */ 
/* 1166 */       if (acct == null) {
/* 1167 */         throw AccountServiceException.NO_SUCH_ACCOUNT(args[1]);
/*      */       }
/*      */       break;
/*      */     case REMOVE_ACCOUNT_LOGGER: 
/* 1171 */       alo = parseAccountLoggerOptions(args);
/* 1172 */       if (!this.command.checkArgsLength(alo.args)) {
/* 1173 */         usage();
/* 1174 */         return true;
/*      */       }
/* 1176 */       doRemoveAccountLogger(alo);
/* 1177 */       break;
/*      */     case REMOVE_CONFIG_SMIME_CONFIG: 
/* 1179 */       doRemoveConfigSMIMEConfig(args);
/* 1180 */       break;
/*      */     case REMOVE_DOMAIN_SMIME_CONFIG: 
/* 1182 */       doRemoveDomainSMIMEConfig(args);
/* 1183 */       break;
/*      */     case RENAME_ACCOUNT: 
/* 1185 */       doRenameAccount(args);
/* 1186 */       break;
/*      */     case RENAME_COS: 
/* 1188 */       this.prov.renameCos(lookupCos(args[1]).getId(), args[2]);
/* 1189 */       break;
/*      */     case RENAME_DOMAIN: 
/* 1191 */       doRenameDomain(args);
/* 1192 */       break;
/*      */     case RENAME_UCSERVICE: 
/* 1194 */       this.prov.renameUCService(lookupUCService(args[1]).getId(), args[2]);
/* 1195 */       break;
/*      */     case SET_ACCOUNT_COS: 
/* 1197 */       this.prov.setCOS(lookupAccount(args[1]), lookupCos(args[2]));
/* 1198 */       break;
/*      */     case SET_SERVER_OFFLINE: 
/* 1200 */       doSetServerOffline(args);
/* 1201 */       break;
/*      */     case SET_LOCAL_SERVER_ONLINE: 
/* 1203 */       doSetLocalServerOnline();
/* 1204 */       break;
/*      */     case SEARCH_ACCOUNTS: 
/* 1206 */       doSearchAccounts(args);
/* 1207 */       break;
/*      */     case SEARCH_GAL: 
/* 1209 */       doSearchGal(args);
/* 1210 */       break;
/*      */     case SYNC_GAL: 
/* 1212 */       doSyncGal(args);
/* 1213 */       break;
/*      */     case SET_PASSWORD: 
/* 1215 */       Provisioning.SetPasswordResult result = this.prov.setPassword(lookupAccount(args[1]), args[2]);
/* 1216 */       if (result.hasMessage()) {
/* 1217 */         console.println(result.getMessage());
/*      */       }
/*      */       break;
/*      */     case CHECK_PASSWORD_STRENGTH: 
/* 1221 */       this.prov.checkPasswordStrength(lookupAccount(args[1]), args[2]);
/* 1222 */       console.println("Password passed strength check.");
/* 1223 */       break;
/*      */     case CREATE_DISTRIBUTION_LIST: 
/* 1225 */       console.println(this.prov.createGroup(args[1], getMapAndCheck(args, 2, true), false).getId());
/* 1226 */       break;
/*      */     case CREATE_DYNAMIC_DISTRIBUTION_LIST: 
/* 1228 */       console.println(this.prov.createGroup(args[1], getMapAndCheck(args, 2, true), true).getId());
/* 1229 */       break;
/*      */     case CREATE_DISTRIBUTION_LISTS_BULK: 
/* 1231 */       doCreateDistributionListsBulk(args);
/* 1232 */       break;
/*      */     case GET_ALL_DISTRIBUTION_LISTS: 
/* 1234 */       doGetAllDistributionLists(args);
/* 1235 */       break;
/*      */     case GET_DISTRIBUTION_LIST: 
/* 1237 */       dumpGroup(lookupGroup(args[1]), getArgNameSet(args, 2));
/* 1238 */       break;
/*      */     case GET_ALL_XMPP_COMPONENTS: 
/* 1240 */       doGetAllXMPPComponents();
/* 1241 */       break;
/*      */     case MODIFY_DISTRIBUTION_LIST: 
/* 1243 */       this.prov.modifyAttrs(lookupGroup(args[1]), getMapAndCheck(args, 2, false), true);
/* 1244 */       break;
/*      */     case DELETE_DISTRIBUTION_LIST: 
/* 1246 */       this.prov.deleteGroup(lookupGroup(args[1]).getId());
/* 1247 */       break;
/*      */     case ADD_DISTRIBUTION_LIST_MEMBER: 
/* 1249 */       members = new String[args.length - 2];
/* 1250 */       System.arraycopy(args, 2, members, 0, args.length - 2);
/* 1251 */       this.prov.addGroupMembers(lookupGroup(args[1]), members);
/* 1252 */       break;
/*      */     case REMOVE_DISTRIBUTION_LIST_MEMBER: 
/* 1254 */       members = new String[args.length - 2];
/* 1255 */       System.arraycopy(args, 2, members, 0, args.length - 2);
/* 1256 */       this.prov.removeGroupMembers(lookupGroup(args[1]), members);
/* 1257 */       break;
/*      */     case CREATE_BULK_ACCOUNTS: 
/* 1259 */       doCreateAccountsBulk(args);
/* 1260 */       break;
/*      */     case ADD_DISTRIBUTION_LIST_ALIAS: 
/* 1262 */       this.prov.addGroupAlias(lookupGroup(args[1]), args[2]);
/* 1263 */       break;
/*      */     case REMOVE_DISTRIBUTION_LIST_ALIAS: 
/* 1265 */       Group dl = lookupGroup(args[1], false);
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */       try
/*      */       {
/* 1273 */         this.prov.removeGroupAlias(dl, args[2]);
/*      */       } catch (ServiceException e) {
/* 1275 */         if ((dl != null) || (!"account.NO_SUCH_DISTRIBUTION_LIST".equals(e.getCode()))) {
/* 1276 */           throw e;
/*      */         }
/*      */       }
/*      */       
/* 1280 */       if (dl == null) {
/* 1281 */         throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(args[1]);
/*      */       }
/*      */       break;
/*      */     case RENAME_DISTRIBUTION_LIST: 
/* 1285 */       this.prov.renameGroup(lookupGroup(args[1]).getId(), args[2]);
/* 1286 */       break;
/*      */     case CREATE_CALENDAR_RESOURCE: 
/* 1288 */       console.println(this.prov.createCalendarResource(args[1], args[2].isEmpty() ? null : args[2], getMapAndCheck(args, 3, true)).getId());
/*      */       
/* 1290 */       break;
/*      */     case DELETE_CALENDAR_RESOURCE: 
/* 1292 */       this.prov.deleteCalendarResource(lookupCalendarResource(args[1]).getId());
/* 1293 */       break;
/*      */     case MODIFY_CALENDAR_RESOURCE: 
/* 1295 */       this.prov.modifyAttrs(lookupCalendarResource(args[1]), getMapAndCheck(args, 2, false), true);
/* 1296 */       break;
/*      */     case RENAME_CALENDAR_RESOURCE: 
/* 1298 */       this.prov.renameCalendarResource(lookupCalendarResource(args[1]).getId(), args[2]);
/* 1299 */       break;
/*      */     case GET_CALENDAR_RESOURCE: 
/* 1301 */       dumpCalendarResource(lookupCalendarResource(args[1]), true, getArgNameSet(args, 2));
/* 1302 */       break;
/*      */     case GET_ALL_CALENDAR_RESOURCES: 
/* 1304 */       doGetAllCalendarResources(args);
/* 1305 */       break;
/*      */     case SEARCH_CALENDAR_RESOURCES: 
/* 1307 */       doSearchCalendarResources(args);
/* 1308 */       break;
/*      */     case GET_SHARE_INFO: 
/* 1310 */       doGetShareInfo(args);
/* 1311 */       break;
/*      */     case GET_SPNEGO_DOMAIN: 
/* 1313 */       doGetSpnegoDomain();
/* 1314 */       break;
/*      */     case GET_QUOTA_USAGE: 
/* 1316 */       doGetQuotaUsage(args);
/* 1317 */       break;
/*      */     case GET_MAILBOX_INFO: 
/* 1319 */       doGetMailboxInfo(args);
/* 1320 */       break;
/*      */     case REINDEX_MAILBOX: 
/* 1322 */       doReIndexMailbox(args);
/* 1323 */       break;
/*      */     case COMPACT_INBOX_MAILBOX: 
/* 1325 */       doCompactIndexMailbox(args);
/* 1326 */       break;
/*      */     case VERIFY_INDEX: 
/* 1328 */       doVerifyIndex(args);
/* 1329 */       break;
/*      */     case GET_INDEX_STATS: 
/* 1331 */       doGetIndexStats(args);
/* 1332 */       break;
/*      */     case RECALCULATE_MAILBOX_COUNTS: 
/* 1334 */       doRecalculateMailboxCounts(args);
/* 1335 */       break;
/*      */     case SELECT_MAILBOX: 
/* 1337 */       if (!(this.prov instanceof SoapProvisioning)) {
/* 1338 */         throwSoapOnly();
/*      */       }
/* 1340 */       ZMailboxUtil util = new ZMailboxUtil();
/* 1341 */       util.setVerbose(this.verboseMode);
/* 1342 */       util.setDebug(this.debugLevel != SoapDebugLevel.none);
/* 1343 */       boolean smInteractive = (this.interactiveMode) && (args.length < 3);
/* 1344 */       util.setInteractive(smInteractive);
/* 1345 */       util.selectMailbox(args[1], (SoapProvisioning)this.prov);
/* 1346 */       if (smInteractive) {
/* 1347 */         util.interactive(this.cliReader);
/* 1348 */       } else if (args.length > 2) {
/* 1349 */         String[] newArgs = new String[args.length - 2];
/* 1350 */         System.arraycopy(args, 2, newArgs, 0, newArgs.length);
/* 1351 */         util.execute(newArgs);
/*      */       } else {
/* 1353 */         throw ZClientException.CLIENT_ERROR("command only valid in interactive mode or with arguments", null);
/*      */       }
/*      */       break;
/*      */     case GET_ALL_MTA_AUTH_URLS: 
/* 1357 */       doGetAllMtaAuthURLs();
/* 1358 */       break;
/*      */     case GET_ALL_REVERSE_PROXY_URLS: 
/* 1360 */       doGetAllReverseProxyURLs();
/* 1361 */       break;
/*      */     case GET_ALL_REVERSE_PROXY_BACKENDS: 
/* 1363 */       doGetAllReverseProxyBackends();
/* 1364 */       break;
/*      */     case GET_ALL_REVERSE_PROXY_DOMAINS: 
/* 1366 */       doGetAllReverseProxyDomains();
/* 1367 */       break;
/*      */     case GET_ALL_MEMCACHED_SERVERS: 
/* 1369 */       doGetAllMemcachedServers();
/* 1370 */       break;
/*      */     case RELOAD_MEMCACHED_CLIENT_CONFIG: 
/* 1372 */       doReloadMemcachedClientConfig(args);
/* 1373 */       break;
/*      */     case GET_MEMCACHED_CLIENT_CONFIG: 
/* 1375 */       doGetMemcachedClientConfig(args);
/* 1376 */       break;
/*      */     case GET_AUTH_TOKEN_INFO: 
/* 1378 */       doGetAuthTokenInfo(args);
/* 1379 */       break;
/*      */     case UPDATE_PRESENCE_SESSION_ID: 
/* 1381 */       doUpdatePresenceSessionId(args);
/* 1382 */       break;
/*      */     
/*      */     case SOAP: 
/* 1385 */       SoapProvisioning sp = new SoapProvisioning();
/* 1386 */       sp.soapSetURI("https://localhost:" + this.serverPort + "/service/admin/soap/");
/* 1387 */       sp.soapZimbraAdminAuthenticate();
/* 1388 */       this.prov = sp;
/* 1389 */       break;
/*      */     
/*      */     case LDAP: 
/* 1392 */       this.prov = Provisioning.getInstance();
/* 1393 */       break;
/*      */     case RESET_ALL_LOGGERS: 
/* 1395 */       doResetAllLoggers(args);
/* 1396 */       break;
/*      */     case UNLOCK_MAILBOX: 
/* 1398 */       doUnlockMailbox(args);
/* 1399 */       break;
/*      */     default: 
/* 1401 */       return false;
/*      */     }
/* 1403 */     return true;
/*      */   }
/*      */   
/* 1406 */   private void sendMailboxLockoutRequest(String acctName, String server, String operation) throws ServiceException, IOException { LockoutMailboxRequest req = LockoutMailboxRequest.create(AccountNameSelector.fromName(acctName));
/* 1407 */     req.setOperation(operation);
/* 1408 */     String url = URLUtil.getAdminURL(server);
/* 1409 */     ZAuthToken token = ((SoapProvisioning)this.prov).getAuthToken();
/* 1410 */     SoapHttpTransport transport = new SoapHttpTransport(url);
/* 1411 */     transport.setAuthToken(token);
/* 1412 */     transport.invokeWithoutSession(JaxbUtil.jaxbToElement(req));
/*      */   }
/*      */   
/*      */   private void doUnlockMailbox(String[] args) throws ServiceException {
/* 1416 */     String accountVal = null;
/* 1417 */     if (args.length > 1) {
/* 1418 */       accountVal = args[1];
/*      */     } else {
/* 1420 */       usage();
/* 1421 */       return;
/*      */     }
/*      */     
/* 1424 */     if (accountVal != null) {
/* 1425 */       Account acct = lookupAccount(accountVal);
/* 1426 */       if (!acct.getAccountStatus().isActive()) {
/* 1427 */         throw ServiceException.FAILURE(String.format("Cannot unlock mailbox for account %s. Account status must be %s. Curent account status is %s. You must change the value of zimbraAccountStatus to '%s' first", new Object[] { accountVal, ZAttrProvisioning.AccountStatus.active, acct.getAccountStatus(), ZAttrProvisioning.AccountStatus.active }), null);
/*      */       }
/*      */       
/*      */ 
/* 1431 */       String accName = acct.getName();
/* 1432 */       String server = acct.getMailHost();
/*      */       try {
/* 1434 */         sendMailboxLockoutRequest(accName, server, "end");
/*      */       } catch (ServiceException e) {
/* 1436 */         if ("service.UNKNOWN_DOCUMENT".equals(e.getCode()))
/* 1437 */           throw ServiceException.FAILURE("source server version does not support LockoutMailboxRequest", e);
/* 1438 */         if ("service.NOT_FOUND".equals(e.getCode())) {
/* 1439 */           printOutput("Warning: " + e.getMessage());
/*      */         } else {
/* 1441 */           throw e;
/*      */         }
/*      */       } catch (IOException e) {
/* 1444 */         throw ServiceException.FAILURE(String.format("Error sending %s (operation = %s) request for %s to %s", new Object[] { "LockoutMailboxRequest", "end", accountVal, server }), e);
/*      */       }
/*      */       
/*      */ 
/* 1448 */       if (args.length > 2)
/*      */       {
/* 1450 */         acct.setAccountStatus(ZAttrProvisioning.AccountStatus.maintenance);
/*      */         try {
/* 1452 */           sendMailboxLockoutRequest(accName, server, "start");
/*      */         } catch (IOException e) {
/* 1454 */           throw ServiceException.FAILURE(String.format("Error sending %s (opertion = %s) request for %s to %s.\n Warning: Account is left in maintenance state!", new Object[] { "LockoutMailboxRequest", "start", accountVal, server }), e);
/*      */         }
/*      */         
/*      */ 
/* 1458 */         String targetServer = args[2];
/*      */         try {
/* 1460 */           UnregisterMailboxMoveOutRequest unregisterReq = UnregisterMailboxMoveOutRequest.create(MailboxMoveSpec.createForNameAndTarget(accName, targetServer));
/* 1461 */           String url = URLUtil.getAdminURL(server);
/* 1462 */           ZAuthToken token = ((SoapProvisioning)this.prov).getAuthToken();
/* 1463 */           SoapHttpTransport transport = new SoapHttpTransport(url);
/* 1464 */           transport.setAuthToken(token);
/* 1465 */           transport.invokeWithoutSession(JaxbUtil.jaxbToElement(unregisterReq));
/*      */         } catch (ServiceException e) {
/* 1467 */           if ("service.UNKNOWN_DOCUMENT".equals(e.getCode())) {
/* 1468 */             throw ServiceException.FAILURE(String.format("target server version does not support %s.", new Object[] { "UnregisterMailboxMoveOutRequest" }), e);
/*      */           }
/* 1470 */           throw ServiceException.FAILURE("Failed to unregister mailbox moveout", e);
/*      */         }
/*      */         catch (IOException e) {
/* 1473 */           throw ServiceException.FAILURE(String.format("Error sending %s request for %s to %s.", new Object[] { "UnregisterMailboxMoveOutRequest", accountVal, server }), e);
/*      */         }
/*      */         finally {
/*      */           try {
/* 1477 */             sendMailboxLockoutRequest(accName, server, "end");
/*      */           }
/*      */           catch (ServiceException e) {
/* 1480 */             if ("service.UNKNOWN_DOCUMENT".equals(e.getCode())) {
/* 1481 */               printError("source server version does not support LockoutMailboxRequest");
/*      */             } else {
/* 1483 */               printError(String.format("Error: failed to unregister mailbox moveout.\n Exception: %s.", new Object[] { e.getMessage() }));
/*      */             }
/*      */           } catch (IOException e) {
/* 1486 */             printError(String.format("Error sending %s (operation = %s) request for %s to %s after unregistering moveout. Exception: %s", new Object[] { "LockoutMailboxRequest", "end", accountVal, server, e.getMessage() }));
/*      */           }
/*      */           
/* 1489 */           acct.setAccountStatus(ZAttrProvisioning.AccountStatus.active);
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetDomain(String[] args) throws ServiceException {
/* 1496 */     boolean applyDefault = true;
/*      */     
/* 1498 */     int i = 1;
/* 1499 */     while (i < args.length) {
/* 1500 */       String arg = args[i];
/* 1501 */       if (!arg.equals("-e")) break;
/* 1502 */       applyDefault = false;
/*      */       
/*      */ 
/*      */ 
/* 1506 */       i++;
/*      */     }
/* 1508 */     if (i >= args.length) {
/* 1509 */       usage();
/* 1510 */       return;
/*      */     }
/* 1512 */     dumpDomain(lookupDomain(args[i], this.prov, applyDefault), applyDefault, getArgNameSet(args, i + 1));
/*      */   }
/*      */   
/*      */   private void doGetDomainInfo(String[] args) throws ServiceException {
/* 1516 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1517 */       throwSoapOnly();
/*      */     }
/* 1519 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1520 */     Key.DomainBy by = Key.DomainBy.fromString(args[1]);
/* 1521 */     String key = args[2];
/* 1522 */     Domain domain = sp.getDomainInfo(by, key);
/* 1523 */     if (domain == null) {
/* 1524 */       throw AccountServiceException.NO_SUCH_DOMAIN(key);
/*      */     }
/* 1526 */     dumpDomain(domain, getArgNameSet(args, 3));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private void doRenameDomain(String[] args)
/*      */     throws ServiceException
/*      */   {
/* 1535 */     if (!this.useLdapMaster) {
/* 1536 */       ((LdapProv)this.prov).alwaysUseMaster();
/*      */     }
/*      */     
/* 1539 */     LdapProv lp = (LdapProv)this.prov;
/* 1540 */     Domain domain = lookupDomain(args[1]);
/* 1541 */     lp.renameDomain(domain.getId(), args[2]);
/* 1542 */     printOutput("domain " + args[1] + " renamed to " + args[2]);
/*      */   }
/*      */   
/*      */   private void doGetQuotaUsage(String[] args) throws ServiceException {
/* 1546 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1547 */       throwSoapOnly();
/*      */     }
/* 1549 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1550 */     List<SoapProvisioning.QuotaUsage> result = sp.getQuotaUsage(args[1]);
/* 1551 */     for (SoapProvisioning.QuotaUsage u : result) {
/* 1552 */       console.printf("%s %d %d\n", new Object[] { u.getName(), Long.valueOf(u.getLimit()), Long.valueOf(u.getUsed()) });
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetMailboxInfo(String[] args) throws ServiceException {
/* 1557 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1558 */       throwSoapOnly();
/*      */     }
/* 1560 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1561 */     Account acct = lookupAccount(args[1]);
/* 1562 */     SoapProvisioning.MailboxInfo info = sp.getMailbox(acct);
/* 1563 */     console.printf("mailboxId: %s\nquotaUsed: %d\n", new Object[] { info.getMailboxId(), Long.valueOf(info.getUsed()) });
/*      */   }
/*      */   
/*      */   private void doReIndexMailbox(String[] args) throws ServiceException {
/* 1567 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1568 */       throwSoapOnly();
/*      */     }
/* 1570 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1571 */     Account acct = lookupAccount(args[1]);
/* 1572 */     SoapProvisioning.ReIndexBy by = null;
/* 1573 */     String[] values = null;
/* 1574 */     if (args.length > 3) {
/*      */       try {
/* 1576 */         by = SoapProvisioning.ReIndexBy.valueOf(args[3]);
/*      */       } catch (IllegalArgumentException e) {
/* 1578 */         throw ServiceException.INVALID_REQUEST("invalid reindex-by", null);
/*      */       }
/* 1580 */       if (args.length > 4) {
/* 1581 */         values = new String[args.length - 4];
/* 1582 */         System.arraycopy(args, 4, values, 0, args.length - 4);
/*      */       } else {
/* 1584 */         throw ServiceException.INVALID_REQUEST("missing reindex-by values", null);
/*      */       }
/*      */     }
/* 1587 */     SoapProvisioning.ReIndexInfo info = sp.reIndex(acct, args[2], by, values);
/* 1588 */     SoapProvisioning.ReIndexInfo.Progress progress = info.getProgress();
/* 1589 */     console.printf("status: %s\n", new Object[] { info.getStatus() });
/* 1590 */     if (progress != null) {
/* 1591 */       console.printf("progress: numSucceeded=%d, numFailed=%d, numRemaining=%d\n", new Object[] { Long.valueOf(progress.getNumSucceeded()), Long.valueOf(progress.getNumFailed()), Long.valueOf(progress.getNumRemaining()) });
/*      */     }
/*      */   }
/*      */   
/*      */   private void doCompactIndexMailbox(String[] args) throws ServiceException
/*      */   {
/* 1597 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1598 */       throwSoapOnly();
/*      */     }
/* 1600 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1601 */     Account acct = lookupAccount(args[1]);
/* 1602 */     String status = sp.compactIndex(acct, args[2]);
/* 1603 */     console.printf("status: %s\n", new Object[] { status });
/*      */   }
/*      */   
/*      */   private void doVerifyIndex(String[] args) throws ServiceException {
/* 1607 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1608 */       throwSoapOnly();
/*      */     }
/* 1610 */     console.println("Verifying, on a large index it can take quite a long time...");
/* 1611 */     SoapProvisioning soap = (SoapProvisioning)this.prov;
/* 1612 */     SoapProvisioning.VerifyIndexResult result = soap.verifyIndex(lookupAccount(args[1]));
/* 1613 */     console.println();
/* 1614 */     console.print(result.message);
/* 1615 */     if (!result.status) {
/* 1616 */       throw ServiceException.FAILURE("The index may be corrupted. Run reIndexMailbox(rim) to repair.", null);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetIndexStats(String[] args) throws ServiceException {
/* 1621 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1622 */       throwSoapOnly();
/*      */     }
/* 1624 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1625 */     Account acct = lookupAccount(args[1]);
/* 1626 */     SoapProvisioning.IndexStatsInfo stats = sp.getIndexStats(acct);
/* 1627 */     console.printf("stats: maxDocs:%d numDeletedDocs:%d\n", new Object[] { Integer.valueOf(stats.getMaxDocs()), Integer.valueOf(stats.getNumDeletedDocs()) });
/*      */   }
/*      */   
/*      */   private void doRecalculateMailboxCounts(String[] args) throws ServiceException {
/* 1631 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1632 */       throwSoapOnly();
/*      */     }
/* 1634 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1635 */     Account account = lookupAccount(args[1]);
/* 1636 */     long quotaUsed = sp.recalculateMailboxCounts(account);
/* 1637 */     console.printf("account: " + account.getName() + "\nquotaUsed: " + quotaUsed + "\n", new Object[0]);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private AccountLoggerOptions parseAccountLoggerOptions(String[] args)
/*      */     throws ServiceException
/*      */   {
/* 1651 */     AccountLoggerOptions alo = new AccountLoggerOptions(null);
/* 1652 */     if ((args.length > 1) && ((args[1].equals("-s")) || (args[1].equals("--server")))) {
/* 1653 */       if (args.length == 2) {
/* 1654 */         throw ServiceException.FAILURE("Server name not specified.", null);
/*      */       }
/* 1656 */       alo.server = args[2];
/*      */       
/* 1658 */       int numArgs = args.length - 2;
/* 1659 */       alo.args = new String[numArgs];
/* 1660 */       alo.args[0] = args[0];
/* 1661 */       for (int i = 1; i < numArgs; i++) {
/* 1662 */         alo.args[i] = args[(i + 2)];
/*      */       }
/*      */     } else {
/* 1665 */       alo.args = args;
/*      */     }
/* 1667 */     return alo;
/*      */   }
/*      */   
/*      */   private void doAddAccountLogger(AccountLoggerOptions alo) throws ServiceException {
/* 1671 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1672 */       throwSoapOnly();
/*      */     }
/* 1674 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1675 */     Account acct = lookupAccount(alo.args[1]);
/* 1676 */     sp.addAccountLogger(acct, alo.args[2], alo.args[3], alo.server);
/*      */   }
/*      */   
/*      */   private void doGetAccountLoggers(AccountLoggerOptions alo) throws ServiceException {
/* 1680 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1681 */       throwSoapOnly();
/*      */     }
/* 1683 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1684 */     Account acct = lookupAccount(alo.args[1]);
/* 1685 */     for (AccountLogger accountLogger : sp.getAccountLoggers(acct, alo.server)) {
/* 1686 */       console.printf("%s=%s\n", new Object[] { accountLogger.getCategory(), accountLogger.getLevel() });
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllAccountLoggers(AccountLoggerOptions alo) throws ServiceException {
/* 1691 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1692 */       throwSoapOnly();
/*      */     }
/* 1694 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/*      */     
/* 1696 */     Map<String, List<AccountLogger>> allLoggers = sp.getAllAccountLoggers(alo.server);
/* 1697 */     for (String accountName : allLoggers.keySet()) {
/* 1698 */       console.printf("# name %s\n", new Object[] { accountName });
/* 1699 */       for (AccountLogger logger : (List)allLoggers.get(accountName)) {
/* 1700 */         console.printf("%s=%s\n", new Object[] { logger.getCategory(), logger.getLevel() });
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doRemoveAccountLogger(AccountLoggerOptions alo) throws ServiceException {
/* 1706 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1707 */       throwSoapOnly();
/*      */     }
/* 1709 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 1710 */     Account acct = null;
/* 1711 */     String category = null;
/* 1712 */     if (alo.args.length == 2)
/*      */     {
/* 1714 */       String arg = alo.args[1];
/* 1715 */       if ((arg.startsWith("zimbra.")) || (arg.startsWith("com.zimbra"))) {
/* 1716 */         category = arg;
/*      */       } else {
/* 1718 */         acct = lookupAccount(alo.args[1]);
/*      */       }
/*      */     }
/* 1721 */     if (alo.args.length == 3) {
/* 1722 */       acct = lookupAccount(alo.args[1]);
/* 1723 */       category = alo.args[2];
/*      */     }
/* 1725 */     sp.removeAccountLoggers(acct, category, alo.server);
/*      */   }
/*      */   
/*      */   private void doResetAllLoggers(String[] args) throws ServiceException {
/* 1729 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1730 */       throwSoapOnly();
/*      */     }
/* 1732 */     SoapProvisioning sprov = (SoapProvisioning)this.prov;
/* 1733 */     String server = null;
/* 1734 */     if ((args.length > 1) && (("-s".equals(args[1])) || ("--server".equals(args[1])))) {
/* 1735 */       server = args.length > 0 ? args[2] : null;
/*      */     }
/* 1737 */     sprov.resetAllLoggers(server);
/*      */   }
/*      */   
/*      */   private void doCreateAccountsBulk(String[] args) throws ServiceException {
/* 1741 */     if (args.length < 3) {
/* 1742 */       usage();
/*      */     } else {
/* 1744 */       String domain = args[1];
/* 1745 */       String password = "test123";
/* 1746 */       String nameMask = args[2];
/* 1747 */       int numAccounts = Integer.parseInt(args[3]);
/* 1748 */       for (int ix = 0; ix < numAccounts; ix++) {
/* 1749 */         String name = nameMask + Integer.toString(ix) + "@" + domain;
/* 1750 */         Map<String, Object> attrs = new HashMap();
/* 1751 */         String displayName = nameMask + " N. " + Integer.toString(ix);
/* 1752 */         StringUtil.addToMultiMap(attrs, "displayName", displayName);
/* 1753 */         Account account = this.prov.createAccount(name, password, attrs);
/* 1754 */         console.println(account.getId());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private Domain doCreateAliasDomain(String aliasDomain, String localDoamin, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 1761 */     Domain local = lookupDomain(localDoamin);
/* 1762 */     if (!local.isLocal()) {
/* 1763 */       throw ServiceException.INVALID_REQUEST("target domain must be a local domain", null);
/*      */     }
/* 1765 */     attrs.put("zimbraDomainType", ZAttrProvisioning.DomainType.alias.name());
/* 1766 */     attrs.put("zimbraDomainAliasTargetId", local.getId());
/* 1767 */     return this.prov.createDomain(aliasDomain, attrs);
/*      */   }
/*      */   
/*      */   private void doGetAccount(String[] args) throws ServiceException {
/* 1771 */     boolean applyDefault = true;
/* 1772 */     int acctPos = 1;
/*      */     
/* 1774 */     if (args[1].equals("-e")) {
/* 1775 */       if (args.length > 1) {
/* 1776 */         applyDefault = false;
/* 1777 */         acctPos = 2;
/*      */       } else {
/* 1779 */         usage();
/* 1780 */         return;
/*      */       }
/*      */     }
/*      */     
/* 1784 */     dumpAccount(lookupAccount(args[acctPos], true, applyDefault), applyDefault, getArgNameSet(args, acctPos + 1));
/*      */   }
/*      */   
/*      */   private void doGetAccountMembership(String[] args) throws ServiceException {
/* 1788 */     String key = null;
/* 1789 */     boolean idsOnly = false;
/* 1790 */     if (args.length > 2) {
/* 1791 */       idsOnly = args[1].equals("-i");
/* 1792 */       key = args[2];
/*      */     } else {
/* 1794 */       key = args[1];
/*      */     }
/* 1796 */     Account account = lookupAccount(key);
/* 1797 */     HashMap<String, String> via; if (idsOnly) {
/* 1798 */       Set<String> lists = this.prov.getGroups(account);
/* 1799 */       for (String id : lists) {
/* 1800 */         console.println(id);
/*      */       }
/*      */     } else {
/* 1803 */       via = new HashMap();
/* 1804 */       List<Group> groups = this.prov.getGroups(account, false, via);
/* 1805 */       for (Group group : groups) {
/* 1806 */         String viaDl = (String)via.get(group.getName());
/* 1807 */         if (viaDl != null) {
/* 1808 */           console.println(group.getName() + " (via " + viaDl + ")");
/*      */         } else
/* 1810 */           console.println(group.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private class AccountLoggerOptions { String server;
/*      */     String[] args;
/*      */     
/*      */     private AccountLoggerOptions() {} }
/*      */   
/*      */   private static class ShareInfoVisitor implements Provisioning.PublishedShareInfoVisitor { private static final String mFormat = "%-36.36s %-15.15s %-15.15s %-5.5s %-20.20s %-10.10s %-10.10s %-10.10s %-5.5s %-5.5s %-36.36s %-15.15s %-15.15s\n";
/*      */     
/* 1822 */     private static void printHeadings() { ProvUtil.console.printf("%-36.36s %-15.15s %-15.15s %-5.5s %-20.20s %-10.10s %-10.10s %-10.10s %-5.5s %-5.5s %-36.36s %-15.15s %-15.15s\n", new Object[] { "owner id", "owner email", "owner display", "id", "path", "view", "type", "rights", "mid", "gt", "grantee id", "grantee name", "grantee display" });
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1837 */       ProvUtil.console.printf("%-36.36s %-15.15s %-15.15s %-5.5s %-20.20s %-10.10s %-10.10s %-10.10s %-5.5s %-5.5s %-36.36s %-15.15s %-15.15s\n", new Object[] { "------------------------------------", "---------------", "---------------", "-----", "--------------------", "----------", "----------", "----------", "-----", "-----", "------------------------------------", "---------------", "---------------" });
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     public void visit(ShareInfoData shareInfoData)
/*      */       throws ServiceException
/*      */     {
/* 1855 */       ProvUtil.console.printf("%-36.36s %-15.15s %-15.15s %-5.5s %-20.20s %-10.10s %-10.10s %-10.10s %-5.5s %-5.5s %-36.36s %-15.15s %-15.15s\n", new Object[] { shareInfoData.getOwnerAcctId(), shareInfoData.getOwnerAcctEmail(), shareInfoData.getOwnerAcctDisplayName(), String.valueOf(shareInfoData.getItemId()), shareInfoData.getPath(), shareInfoData.getFolderDefaultView(), shareInfoData.getType().name(), shareInfoData.getRights(), shareInfoData.getMountpointId_zmprov_only(), shareInfoData.getGranteeType(), shareInfoData.getGranteeId(), shareInfoData.getGranteeName(), shareInfoData.getGranteeDisplayName() });
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private void doGetShareInfo(String[] args)
/*      */     throws ServiceException
/*      */   {
/* 1873 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 1874 */       throwSoapOnly();
/*      */     }
/* 1876 */     Account owner = lookupAccount(args[1]);
/*      */     
/* 1878 */     ShareInfoVisitor.access$200();
/* 1879 */     this.prov.getShareInfo(owner, new ShareInfoVisitor(null));
/*      */   }
/*      */   
/*      */   private void doGetSpnegoDomain() throws ServiceException {
/* 1883 */     Config config = this.prov.getConfig();
/* 1884 */     String spnegoAuthRealm = config.getSpnegoAuthRealm();
/* 1885 */     if (spnegoAuthRealm != null) {
/* 1886 */       Domain domain = this.prov.get(Key.DomainBy.krb5Realm, spnegoAuthRealm);
/* 1887 */       if (domain != null) {
/* 1888 */         console.println(domain.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private boolean confirm(String msg) {
/* 1894 */     if (this.batchMode) {
/* 1895 */       return true;
/*      */     }
/*      */     
/* 1898 */     console.println(msg);
/* 1899 */     console.print("Continue? [Y]es, [N]o: ");
/*      */     
/*      */     try
/*      */     {
/* 1903 */       BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
/* 1904 */       String line = StringUtil.readLine(in);
/* 1905 */       if (("y".equalsIgnoreCase(line)) || ("yes".equalsIgnoreCase(line))) {
/* 1906 */         return true;
/*      */       }
/*      */     } catch (UnsupportedEncodingException e) {
/* 1909 */       e.printStackTrace();
/*      */     } catch (IOException e) {
/* 1911 */       e.printStackTrace();
/*      */     }
/*      */     
/* 1914 */     return false;
/*      */   }
/*      */   
/*      */   private void doDeleteAccount(String[] args) throws ServiceException
/*      */   {
/* 1919 */     if ((this.prov instanceof LdapProv)) {
/* 1920 */       boolean confirmed = confirm("-l option is specified.  Only the LDAP entry of the account will be deleted.\nDB data of the account and associated blobs will not be deleted.\n");
/*      */       
/*      */ 
/*      */ 
/* 1924 */       if (!confirmed) {
/* 1925 */         console.println("aborted");
/* 1926 */         return;
/*      */       }
/*      */     }
/*      */     
/* 1930 */     String key = args[1];
/* 1931 */     Account acct = lookupAccount(key);
/* 1932 */     if ((key.equalsIgnoreCase(acct.getId())) || (key.equalsIgnoreCase(acct.getName())) || (acct.getName().equalsIgnoreCase(key + "@" + acct.getDomainName())))
/*      */     {
/* 1934 */       this.prov.deleteAccount(acct.getId());
/*      */     } else {
/* 1936 */       throw ServiceException.INVALID_REQUEST("argument to deleteAccount must be an account id or the account's primary name", null);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doRenameAccount(String[] args) throws ServiceException
/*      */   {
/* 1942 */     if ((this.prov instanceof LdapProv)) {
/* 1943 */       boolean confirmed = confirm("-l option is specified.  Only the LDAP portion of the account will be deleted.\nDB data of the account will not be renamed.\n");
/*      */       
/*      */ 
/*      */ 
/* 1947 */       if (!confirmed) {
/* 1948 */         console.println("aborted");
/* 1949 */         return;
/*      */       }
/*      */     }
/*      */     
/* 1953 */     this.prov.renameAccount(lookupAccount(args[1]).getId(), args[2]);
/*      */   }
/*      */   
/*      */   private void doGetAccountIdentities(String[] args) throws ServiceException {
/* 1957 */     Account account = lookupAccount(args[1]);
/* 1958 */     Set<String> argNameSet = getArgNameSet(args, 2);
/* 1959 */     for (Identity identity : this.prov.getAllIdentities(account)) {
/* 1960 */       dumpIdentity(identity, argNameSet);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAccountSignatures(String[] args) throws ServiceException {
/* 1965 */     Account account = lookupAccount(args[1]);
/* 1966 */     Set<String> argNameSet = getArgNameSet(args, 2);
/* 1967 */     for (Signature signature : this.prov.getAllSignatures(account)) {
/* 1968 */       dumpSignature(signature, argNameSet);
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpDataSource(DataSource dataSource, Set<String> argNameSet) throws ServiceException {
/* 1973 */     console.println("# name " + dataSource.getName());
/* 1974 */     console.println("# type " + dataSource.getType());
/* 1975 */     Map<String, Object> attrs = dataSource.getAttrs();
/* 1976 */     dumpAttrs(attrs, argNameSet);
/* 1977 */     console.println();
/*      */   }
/*      */   
/*      */   private void doGetAccountDataSources(String[] args) throws ServiceException {
/* 1981 */     Account account = lookupAccount(args[1]);
/* 1982 */     Set<String> attrNameSet = getArgNameSet(args, 2);
/* 1983 */     for (DataSource dataSource : this.prov.getAllDataSources(account))
/* 1984 */       dumpDataSource(dataSource, attrNameSet);
/*      */   }
/*      */   
/*      */   private void doGetDistributionListMembership(Group group) throws ServiceException {
/*      */     String[] members;
/*      */     String[] members;
/* 1990 */     if ((group instanceof DynamicGroup)) {
/* 1991 */       members = ((DynamicGroup)group).getAllMembers(true);
/*      */     } else {
/* 1993 */       members = group.getAllMembers();
/*      */     }
/*      */     
/* 1996 */     int count = members == null ? 0 : members.length;
/* 1997 */     console.println("# distributionList " + group.getName() + " memberCount=" + count);
/* 1998 */     console.println();
/* 1999 */     console.println("members");
/* 2000 */     for (String member : members) {
/* 2001 */       console.println(member);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetConfig(String[] args) throws ServiceException {
/* 2006 */     String key = args[1];
/* 2007 */     Set<String> needAttr = new HashSet();
/* 2008 */     needAttr.add(key);
/* 2009 */     dumpAttrs(this.prov.getConfig(key).getAttrs(), needAttr);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private void doGetAllAccounts(LdapProv ldapProv, Domain domain, Server server, final boolean verbose, final boolean applyDefault, final Set<String> attrNames)
/*      */     throws ServiceException
/*      */   {
/* 2018 */     NamedEntry.Visitor visitor = new NamedEntry.Visitor()
/*      */     {
/*      */       public void visit(NamedEntry entry) throws ServiceException {
/* 2021 */         if (verbose) {
/* 2022 */           ProvUtil.this.dumpAccount((Account)entry, applyDefault, attrNames);
/*      */         } else {
/* 2024 */           ProvUtil.console.println(entry.getName());
/*      */         }
/*      */         
/*      */       }
/* 2028 */     };
/* 2029 */     SearchAccountsOptions options = new SearchAccountsOptions();
/* 2030 */     if (domain != null) {
/* 2031 */       options.setDomain(domain);
/*      */     }
/* 2033 */     options.setIncludeType(SearchAccountsOptions.IncludeType.ACCOUNTS_ONLY);
/* 2034 */     if (!applyDefault) {
/* 2035 */       options.setMakeObjectOpt(SearchDirectoryOptions.MakeObjectOpt.NO_DEFAULTS);
/*      */     }
/*      */     
/* 2038 */     if (server == null) {
/* 2039 */       options.setFilter(ZLdapFilterFactory.getInstance().allAccountsOnly());
/* 2040 */       ldapProv.searchDirectory(options, visitor);
/*      */     } else {
/* 2042 */       ldapProv.searchAccountsOnServer(server, options, visitor);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllAccounts(String[] args) throws ServiceException
/*      */   {
/* 2048 */     LdapProv ldapProv = (LdapProv)this.prov;
/*      */     
/* 2050 */     boolean verbose = false;
/* 2051 */     boolean applyDefault = true;
/* 2052 */     String d = null;
/* 2053 */     String s = null;
/*      */     
/* 2055 */     int i = 1;
/* 2056 */     while (i < args.length) {
/* 2057 */       String arg = args[i];
/* 2058 */       if (arg.equals("-v")) {
/* 2059 */         verbose = true;
/* 2060 */       } else if (arg.equals("-e")) {
/* 2061 */         applyDefault = false;
/* 2062 */       } else if (arg.equals("-s")) {
/* 2063 */         i++;
/* 2064 */         if (i < args.length) {
/* 2065 */           if (s == null) {
/* 2066 */             s = args[i];
/*      */           } else {
/* 2068 */             console.println("invalid arg: " + args[i] + ", already specified -s with " + s);
/* 2069 */             usage();
/*      */           }
/*      */         }
/*      */         else {
/* 2073 */           usage();
/*      */         }
/*      */         
/*      */       }
/* 2077 */       else if (d == null) {
/* 2078 */         d = arg;
/*      */       } else {
/* 2080 */         console.println("invalid arg: " + arg + ", already specified domain: " + d);
/* 2081 */         usage();
/* 2082 */         return;
/*      */       }
/*      */       
/* 2085 */       i++;
/*      */     }
/*      */     
/* 2088 */     if ((!applyDefault) && (!verbose)) {
/* 2089 */       console.println("arg -e is invalid unless -v is also specified");
/* 2090 */       usage();
/* 2091 */       return;
/*      */     }
/*      */     
/* 2094 */     Server server = null;
/* 2095 */     if (s != null) {
/* 2096 */       server = lookupServer(s);
/*      */     }
/* 2098 */     if (d == null) {
/* 2099 */       doGetAllAccounts(ldapProv, null, server, verbose, applyDefault, null);
/*      */     } else {
/* 2101 */       Domain domain = lookupDomain(d, ldapProv);
/* 2102 */       doGetAllAccounts(ldapProv, domain, server, verbose, applyDefault, null);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doSearchAccounts(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 2107 */     boolean verbose = false;
/* 2108 */     int i = 1;
/*      */     
/* 2110 */     if (args[i].equals("-v")) {
/* 2111 */       verbose = true;
/* 2112 */       i++;
/* 2113 */       if (args.length < i - 1) {
/* 2114 */         usage();
/* 2115 */         return;
/*      */       }
/*      */     }
/*      */     
/* 2119 */     if (args.length < i + 1) {
/* 2120 */       usage();
/* 2121 */       return;
/*      */     }
/*      */     
/* 2124 */     String query = args[i];
/*      */     
/* 2126 */     Map<String, Object> attrs = getMap(args, i + 1);
/* 2127 */     String limitStr = (String)attrs.get("limit");
/* 2128 */     int limit = limitStr == null ? Integer.MAX_VALUE : Integer.parseInt(limitStr);
/*      */     
/* 2130 */     String offsetStr = (String)attrs.get("offset");
/* 2131 */     int offset = offsetStr == null ? 0 : Integer.parseInt(offsetStr);
/*      */     
/* 2133 */     String sortBy = (String)attrs.get("sortBy");
/* 2134 */     String sortAscending = (String)attrs.get("sortAscending");
/* 2135 */     boolean isSortAscending = sortAscending != null ? "1".equalsIgnoreCase(sortAscending) : true;
/*      */     
/* 2137 */     String[] attrsToGet = null;
/*      */     
/* 2139 */     String typesStr = (String)attrs.get("types");
/* 2140 */     if (typesStr == null) {
/* 2141 */       typesStr = SearchDirectoryOptions.ObjectType.accounts.name() + "," + SearchDirectoryOptions.ObjectType.aliases.name() + "," + SearchDirectoryOptions.ObjectType.distributionlists.name() + "," + SearchDirectoryOptions.ObjectType.dynamicgroups.name() + "," + SearchDirectoryOptions.ObjectType.resources.name();
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 2148 */     String domainStr = (String)attrs.get("domain");
/*      */     
/* 2150 */     SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(attrsToGet);
/* 2151 */     if (domainStr != null) {
/* 2152 */       Domain d = lookupDomain(domainStr, this.prov);
/* 2153 */       searchOpts.setDomain(d);
/*      */     }
/* 2155 */     searchOpts.setTypes(typesStr);
/* 2156 */     searchOpts.setSortOpt(isSortAscending ? SearchDirectoryOptions.SortOpt.SORT_ASCENDING : SearchDirectoryOptions.SortOpt.SORT_DESCENDING);
/* 2157 */     searchOpts.setSortAttr(sortBy);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/* 2162 */     ZLdapFilterFactory.FilterId filterId = (this.prov instanceof LdapProv) ? ZLdapFilterFactory.FilterId.ADMIN_SEARCH : null;
/* 2163 */     searchOpts.setFilterString(filterId, query);
/* 2164 */     searchOpts.setConvertIDNToAscii(true);
/*      */     
/* 2166 */     List<NamedEntry> accounts = this.prov.searchDirectory(searchOpts);
/*      */     
/* 2168 */     for (int j = offset; (j < offset + limit) && (j < accounts.size()); j++) {
/* 2169 */       NamedEntry account = (NamedEntry)accounts.get(j);
/* 2170 */       if (verbose) {
/* 2171 */         if ((account instanceof Account)) {
/* 2172 */           dumpAccount((Account)account, true, null);
/* 2173 */         } else if ((account instanceof Alias)) {
/* 2174 */           dumpAlias((Alias)account);
/* 2175 */         } else if ((account instanceof DistributionList)) {
/* 2176 */           dumpGroup((DistributionList)account, null);
/* 2177 */         } else if ((account instanceof Domain)) {
/* 2178 */           dumpDomain((Domain)account, null);
/*      */         }
/*      */       } else {
/* 2181 */         console.println(account.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doSyncGal(String[] args) throws ServiceException {
/* 2187 */     String domain = args[1];
/* 2188 */     String token = args.length == 3 ? args[2] : "";
/*      */     
/* 2190 */     Domain d = lookupDomain(domain);
/*      */     
/* 2192 */     Provisioning.SearchGalResult result = null;
/* 2193 */     if ((this.prov instanceof LdapProv)) {
/* 2194 */       GalContact.Visitor visitor = new GalContact.Visitor()
/*      */       {
/*      */         public void visit(GalContact gc) throws ServiceException {
/* 2197 */           ProvUtil.this.dumpContact(gc);
/*      */         }
/* 2199 */       };
/* 2200 */       result = this.prov.syncGal(d, token, visitor);
/*      */     } else {
/* 2202 */       result = ((SoapProvisioning)this.prov).searchGal(d, "", GalSearchType.all, token, 0, 0, null);
/* 2203 */       for (GalContact contact : result.getMatches()) {
/* 2204 */         dumpContact(contact);
/*      */       }
/*      */     }
/*      */     
/* 2208 */     if (result.getToken() != null) {
/* 2209 */       console.println("\n# token = " + result.getToken() + "\n");
/*      */     }
/*      */   }
/*      */   
/*      */   private void doSearchGal(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 2214 */     if (args.length < 3) {
/* 2215 */       usage();
/* 2216 */       return;
/*      */     }
/* 2218 */     String domain = args[1];
/* 2219 */     String query = args[2];
/* 2220 */     Map<String, Object> attrs = getMap(args, 3);
/* 2221 */     String limitStr = (String)attrs.get("limit");
/* 2222 */     int limit = limitStr == null ? 0 : Integer.parseInt(limitStr);
/* 2223 */     String offsetStr = (String)attrs.get("offset");
/* 2224 */     int offset = offsetStr == null ? 0 : Integer.parseInt(offsetStr);
/* 2225 */     String sortBy = (String)attrs.get("sortBy");
/* 2226 */     Domain d = lookupDomain(domain);
/*      */     
/*      */     Provisioning.SearchGalResult result;
/*      */     
/* 2230 */     if ((this.prov instanceof LdapProv)) {
/* 2231 */       if (offsetStr != null) {
/* 2232 */         throw ServiceException.INVALID_REQUEST("offset is not supported with -l", null);
/*      */       }
/*      */       
/* 2235 */       if (sortBy != null) {
/* 2236 */         throw ServiceException.INVALID_REQUEST("sortBy is not supported with -l", null);
/*      */       }
/*      */       
/* 2239 */       GalContact.Visitor visitor = new GalContact.Visitor()
/*      */       {
/*      */         public void visit(GalContact gc) throws ServiceException {
/* 2242 */           ProvUtil.this.dumpContact(gc);
/*      */         }
/* 2244 */       };
/* 2245 */       result = this.prov.searchGal(d, query, GalSearchType.all, limit, visitor);
/*      */     }
/*      */     else {
/* 2248 */       Provisioning.SearchGalResult result = ((SoapProvisioning)this.prov).searchGal(d, query, GalSearchType.all, null, limit, offset, sortBy);
/* 2249 */       for (GalContact contact : result.getMatches()) {
/* 2250 */         dumpContact(contact);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doAutoCompleteGal(String[] args) throws ServiceException {
/* 2256 */     String domain = args[1];
/* 2257 */     String query = args[2];
/* 2258 */     int limit = 100;
/*      */     
/* 2260 */     Domain d = lookupDomain(domain);
/*      */     
/* 2262 */     GalContact.Visitor visitor = new GalContact.Visitor()
/*      */     {
/*      */       public void visit(GalContact gc) throws ServiceException {
/* 2265 */         ProvUtil.this.dumpContact(gc);
/*      */       }
/* 2267 */     };
/* 2268 */     Provisioning.SearchGalResult result = this.prov.autoCompleteGal(d, query, GalSearchType.all, limit, visitor);
/*      */   }
/*      */   
/*      */   private void doCountAccount(String[] args) throws ServiceException {
/* 2272 */     String domain = args[1];
/* 2273 */     Domain d = lookupDomain(domain);
/*      */     
/* 2275 */     Provisioning.CountAccountResult result = this.prov.countAccount(d);
/* 2276 */     String formatHeading = "%-20s %-40s %s\n";
/* 2277 */     String format = "%-20s %-40s %d\n";
/* 2278 */     console.printf(formatHeading, new Object[] { "cos name", "cos id", "# of accounts" });
/* 2279 */     console.printf(formatHeading, new Object[] { "--------------------", "----------------------------------------", "--------------------" });
/* 2280 */     for (Provisioning.CountAccountResult.CountAccountByCos c : result.getCountAccountByCos()) {
/* 2281 */       console.printf(format, new Object[] { c.getCosName(), c.getCosId(), Long.valueOf(c.getCount()) });
/*      */     }
/*      */     
/* 2284 */     console.println();
/*      */   }
/*      */   
/*      */   private void doCountObjects(String[] args) throws ServiceException
/*      */   {
/* 2289 */     CountObjectsType type = CountObjectsType.fromString(args[1]);
/*      */     
/* 2291 */     Domain domain = null;
/* 2292 */     UCService ucService = null;
/* 2293 */     int idx = 2;
/* 2294 */     while (args.length > idx) {
/* 2295 */       String arg = args[idx];
/*      */       
/* 2297 */       if (arg.equals("-d")) {
/* 2298 */         if (domain != null) {
/* 2299 */           throw ServiceException.INVALID_REQUEST("domain is already specified as:" + domain.getName(), null);
/*      */         }
/* 2301 */         idx++;
/* 2302 */         if (args.length <= idx) {
/* 2303 */           usage();
/* 2304 */           throw ServiceException.INVALID_REQUEST("expecting domain, not enough args", null);
/*      */         }
/* 2306 */         domain = lookupDomain(args[idx]);
/* 2307 */       } else if (arg.equals("-u")) {
/* 2308 */         if (ucService != null) {
/* 2309 */           throw ServiceException.INVALID_REQUEST("UCService is already specified as:" + ucService.getName(), null);
/*      */         }
/* 2311 */         idx++;
/* 2312 */         if (args.length <= idx) {
/* 2313 */           usage();
/* 2314 */           throw ServiceException.INVALID_REQUEST("expecting UCService, not enough args", null);
/*      */         }
/* 2316 */         ucService = lookupUCService(args[idx]);
/*      */       } else {
/* 2318 */         usage();
/* 2319 */         return;
/*      */       }
/*      */       
/* 2322 */       idx++;
/*      */     }
/*      */     
/* 2325 */     long result = this.prov.countObjects(type, domain, ucService);
/* 2326 */     console.println(result);
/*      */   }
/*      */   
/*      */   private void doGetAllAdminAccounts(String[] args) throws ServiceException {
/* 2330 */     boolean verbose = false;
/* 2331 */     boolean applyDefault = true;
/*      */     
/* 2333 */     int i = 1;
/* 2334 */     while (i < args.length) {
/* 2335 */       String arg = args[i];
/* 2336 */       if (arg.equals("-v")) {
/* 2337 */         verbose = true;
/* 2338 */       } else { if (!arg.equals("-e")) break;
/* 2339 */         applyDefault = false;
/*      */       }
/*      */       
/*      */ 
/* 2343 */       i++;
/*      */     }
/*      */     
/* 2346 */     if ((!applyDefault) && (!verbose)) {
/* 2347 */       console.println("arg -e is invalid unless -v is also specified");
/* 2348 */       usage(); return;
/*      */     }
/*      */     
/*      */     List<Account> accounts;
/*      */     List<Account> accounts;
/* 2353 */     if ((this.prov instanceof SoapProvisioning)) {
/* 2354 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 2355 */       accounts = soapProv.getAllAdminAccounts(applyDefault);
/*      */     } else {
/* 2357 */       accounts = this.prov.getAllAdminAccounts();
/*      */     }
/* 2359 */     Set<String> attrNames = getArgNameSet(args, i);
/* 2360 */     for (Account account : accounts) {
/* 2361 */       if (verbose) {
/* 2362 */         dumpAccount(account, applyDefault, attrNames);
/*      */       } else {
/* 2364 */         console.println(account.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllCos(String[] args) throws ServiceException {
/* 2370 */     boolean verbose = (args.length > 1) && (args[1].equals("-v"));
/* 2371 */     Set<String> attrNames = getArgNameSet(args, verbose ? 2 : 1);
/* 2372 */     List<Cos> allcos = this.prov.getAllCos();
/* 2373 */     for (Cos cos : allcos) {
/* 2374 */       if (verbose) {
/* 2375 */         dumpCos(cos, attrNames);
/*      */       } else {
/* 2377 */         console.println(cos.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpCos(Cos cos, Set<String> attrNames) throws ServiceException {
/* 2383 */     console.println("# name " + cos.getName());
/* 2384 */     Map<String, Object> attrs = cos.getAttrs();
/* 2385 */     dumpAttrs(attrs, attrNames);
/* 2386 */     console.println();
/*      */   }
/*      */   
/*      */   private void doGetAllDomains(String[] args) throws ServiceException {
/* 2390 */     boolean verbose = false;
/* 2391 */     boolean applyDefault = true;
/*      */     
/* 2393 */     int i = 1;
/* 2394 */     while (i < args.length) {
/* 2395 */       String arg = args[i];
/* 2396 */       if (arg.equals("-v")) {
/* 2397 */         verbose = true;
/* 2398 */       } else { if (!arg.equals("-e")) break;
/* 2399 */         applyDefault = false;
/*      */       }
/*      */       
/*      */ 
/* 2403 */       i++;
/*      */     }
/*      */     
/* 2406 */     if ((!applyDefault) && (!verbose)) {
/* 2407 */       console.println("arg -e is invalid unless -v is also specified");
/* 2408 */       usage();
/* 2409 */       return;
/*      */     }
/*      */     
/* 2412 */     Set<String> attrNames = getArgNameSet(args, i);
/*      */     List<Domain> domains;
/*      */     List<Domain> domains;
/* 2415 */     if ((this.prov instanceof SoapProvisioning)) {
/* 2416 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 2417 */       domains = soapProv.getAllDomains(applyDefault);
/*      */     } else {
/* 2419 */       domains = this.prov.getAllDomains();
/*      */     }
/* 2421 */     for (Domain domain : domains) {
/* 2422 */       if (verbose) {
/* 2423 */         dumpDomain(domain, attrNames);
/*      */       } else {
/* 2425 */         console.println(domain.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpDomain(Domain domain, Set<String> attrNames) throws ServiceException {
/* 2431 */     dumpDomain(domain, true, attrNames);
/*      */   }
/*      */   
/*      */   private void dumpDomain(Domain domain, boolean expandConfig, Set<String> attrNames) throws ServiceException {
/* 2435 */     console.println("# name " + domain.getName());
/* 2436 */     Map<String, Object> attrs = domain.getAttrs(expandConfig);
/* 2437 */     dumpAttrs(attrs, attrNames);
/* 2438 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpGroup(Group group, Set<String> attrNames) throws ServiceException {
/*      */     String[] members;
/*      */     String[] members;
/* 2444 */     if ((group instanceof DynamicGroup)) {
/* 2445 */       members = ((DynamicGroup)group).getAllMembers(true);
/*      */     } else {
/* 2447 */       members = group.getAllMembers();
/*      */     }
/*      */     
/* 2450 */     int count = members == null ? 0 : members.length;
/* 2451 */     console.println("# distributionList " + group.getName() + " memberCount=" + count);
/* 2452 */     Map<String, Object> attrs = group.getAttrs();
/* 2453 */     dumpAttrs(attrs, attrNames);
/* 2454 */     console.println();
/* 2455 */     console.println("members");
/* 2456 */     for (String member : members) {
/* 2457 */       console.println(member);
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpAlias(Alias alias) throws ServiceException {
/* 2462 */     console.println("# alias " + alias.getName());
/* 2463 */     Map<String, Object> attrs = alias.getAttrs();
/* 2464 */     dumpAttrs(attrs, null);
/*      */   }
/*      */   
/*      */   private void doGetRight(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 2468 */     boolean expandComboRight = false;
/* 2469 */     String right = args[1];
/* 2470 */     if (args.length > 2) {
/* 2471 */       if (args[2].equals("-e")) {
/* 2472 */         expandComboRight = true;
/*      */       } else {
/* 2474 */         throw new ArgException("invalid arguments");
/*      */       }
/*      */     }
/* 2477 */     dumpRight(lookupRight(right), expandComboRight);
/*      */   }
/*      */   
/*      */   private void doGetAllRights(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 2481 */     boolean verbose = false;
/* 2482 */     String targetType = null;
/* 2483 */     String rightClass = null;
/*      */     
/* 2485 */     int i = 1;
/* 2486 */     while (i < args.length) {
/* 2487 */       String arg = args[i];
/* 2488 */       if (arg.equals("-v")) {
/* 2489 */         verbose = true;
/* 2490 */       } else if (arg.equals("-t")) {
/* 2491 */         i++;
/* 2492 */         if (i == args.length) {
/* 2493 */           throw new ArgException("not enough arguments");
/*      */         }
/* 2495 */         targetType = args[i];
/*      */       }
/* 2497 */       else if (arg.equals("-c")) {
/* 2498 */         i++;
/* 2499 */         if (i == args.length) {
/* 2500 */           throw new ArgException("not enough arguments");
/*      */         }
/* 2502 */         rightClass = args[i];
/*      */       }
/*      */       else {
/* 2505 */         throw new ArgException("invalid arg: " + arg);
/*      */       }
/* 2507 */       i++;
/*      */     }
/*      */     
/* 2510 */     List<Right> allRights = this.prov.getAllRights(targetType, false, rightClass);
/* 2511 */     for (Right right : allRights) {
/* 2512 */       if (verbose) {
/* 2513 */         dumpRight(right);
/*      */       } else {
/* 2515 */         console.println(right.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpRight(Right right) {
/* 2521 */     dumpRight(right, true);
/*      */   }
/*      */   
/*      */   private void dumpRight(Right right, boolean expandComboRight) {
/* 2525 */     String tab = "    ";
/* 2526 */     String indent = tab;
/* 2527 */     String indent2 = indent + indent;
/*      */     
/* 2529 */     console.println();
/* 2530 */     console.println("------------------------------");
/*      */     
/* 2532 */     console.println(right.getName());
/* 2533 */     console.println(indent + "      description: " + right.getDesc());
/* 2534 */     console.println(indent + "       right type: " + right.getRightType().name());
/*      */     
/* 2536 */     String targetType = right.getTargetTypeStr();
/* 2537 */     console.println(indent + "   target type(s): " + (targetType == null ? "" : targetType));
/*      */     
/* 2539 */     String grantTargetType = right.getGrantTargetTypeStr();
/* 2540 */     console.println(indent + "grant target type: " + (grantTargetType == null ? "(default)" : grantTargetType));
/*      */     
/*      */ 
/* 2543 */     console.println(indent + "      right class: " + right.getRightClass().name());
/*      */     
/* 2545 */     if (right.isAttrRight()) {
/* 2546 */       AttrRight attrRight = (AttrRight)right;
/* 2547 */       console.println();
/* 2548 */       console.println(indent + "attributes:");
/* 2549 */       if (attrRight.allAttrs()) {
/* 2550 */         console.println(indent2 + "all attributes");
/*      */       } else {
/* 2552 */         for (String attrName : attrRight.getAttrs()) {
/* 2553 */           console.println(indent2 + attrName);
/*      */         }
/*      */       }
/* 2556 */     } else if (right.isComboRight()) {
/* 2557 */       ComboRight comboRight = (ComboRight)right;
/* 2558 */       console.println();
/* 2559 */       console.println(indent + "rights:");
/* 2560 */       dumpComboRight(comboRight, expandComboRight, indent, new HashSet());
/*      */     }
/* 2562 */     console.println();
/*      */     
/* 2564 */     Help help = right.getHelp();
/* 2565 */     if (help != null) {
/* 2566 */       console.println(help.getDesc());
/* 2567 */       List<String> helpItems = help.getItems();
/* 2568 */       for (String helpItem : helpItems)
/*      */       {
/* 2570 */         console.println("- " + helpItem.trim());
/* 2571 */         console.println();
/*      */       }
/*      */     }
/* 2574 */     console.println();
/*      */   }
/*      */   
/*      */ 
/*      */   private void dumpComboRight(ComboRight comboRight, boolean expandComboRight, String indent, Set<String> seen)
/*      */   {
/* 2580 */     if (seen.contains(comboRight.getName())) {
/* 2581 */       console.println("Circular combo right: " + comboRight.getName() + " !!");
/* 2582 */       return;
/*      */     }
/*      */     
/* 2585 */     String indent2 = indent + indent;
/*      */     
/* 2587 */     for (Right r : comboRight.getRights()) {
/* 2588 */       String tt = r.getTargetTypeStr();
/* 2589 */       tt = " (" + tt + ")";
/*      */       
/* 2591 */       console.format("%s %s: %s %s\n", new Object[] { indent2, r.getRightType().name(), r.getName(), tt });
/*      */       
/* 2593 */       seen.add(comboRight.getName());
/*      */       
/* 2595 */       if ((r.isComboRight()) && (expandComboRight)) {
/* 2596 */         dumpComboRight((ComboRight)r, expandComboRight, indent2, seen);
/*      */       }
/*      */       
/* 2599 */       seen.clear();
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetRightsDoc(String[] args) throws ServiceException {
/* 2604 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 2605 */       throwSoapOnly();
/*      */     }
/*      */     
/*      */ 
/* 2609 */     StringBuilder argsDump = new StringBuilder();
/* 2610 */     String[] packages; if (args.length > 1)
/*      */     {
/* 2612 */       String[] packages = new String[args.length - 1];
/* 2613 */       for (int i = 1; i < args.length; i++) {
/* 2614 */         packages[(i - 1)] = args[i];
/* 2615 */         argsDump.append(" " + args[i]);
/*      */       }
/*      */     } else {
/* 2618 */       packages = new String[] { "com.zimbra.cs.service.admin", "com.zimbra.bp", "com.zimbra.cert", "com.zimbra.cs.network", "com.zimbra.cs.network.license.service", "com.zimbra.cs.service.backup", "com.zimbra.cs.service.hsm", "com.zimbra.xmbxsearch" };
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 2630 */     console.println("#");
/* 2631 */     console.println("#  Generated by: zmprov grd" + argsDump);
/* 2632 */     console.println("#");
/* 2633 */     console.println("#  Date: " + DateFormat.getDateInstance(1).format(new Date()));
/* 2634 */     console.println("# ");
/* 2635 */     console.println("#  Pacakges:");
/* 2636 */     for (String pkg : packages) {
/* 2637 */       console.println("#       " + pkg);
/*      */     }
/* 2639 */     console.println("# ");
/* 2640 */     console.println("\n");
/*      */     
/* 2642 */     Map<String, List<Provisioning.RightsDoc>> allDocs = this.prov.getRightsDoc(packages);
/* 2643 */     for (Map.Entry<String, List<Provisioning.RightsDoc>> docs : allDocs.entrySet()) {
/* 2644 */       console.println("========================================");
/* 2645 */       console.println("Package: " + (String)docs.getKey());
/* 2646 */       console.println("========================================");
/* 2647 */       console.println();
/*      */       
/* 2649 */       for (Provisioning.RightsDoc doc : (List)docs.getValue()) {
/* 2650 */         console.println("------------------------------");
/* 2651 */         console.println(doc.getCmd() + "\n");
/*      */         
/* 2653 */         console.println("    Related rights:");
/* 2654 */         for (String r : doc.getRights()) {
/* 2655 */           console.println("        " + r);
/*      */         }
/* 2657 */         console.println();
/* 2658 */         console.println("    Notes:");
/* 2659 */         for (String n : doc.getNotes()) {
/* 2660 */           console.println(FileGenUtil.wrapComments(StringUtil.escapeHtml(n), 70, "        ") + "\n");
/*      */         }
/* 2662 */         console.println();
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllServers(String[] args) throws ServiceException {
/* 2668 */     boolean verbose = false;
/* 2669 */     boolean applyDefault = true;
/* 2670 */     String service = null;
/*      */     
/* 2672 */     int i = 1;
/* 2673 */     while (i < args.length) {
/* 2674 */       String arg = args[i];
/* 2675 */       if (arg.equals("-v")) {
/* 2676 */         verbose = true;
/* 2677 */       } else if (arg.equals("-e")) {
/* 2678 */         applyDefault = false;
/*      */       }
/* 2680 */       else if (service == null) {
/* 2681 */         service = arg;
/*      */       } else {
/* 2683 */         console.println("invalid arg: " + arg + ", already specified service: " + service);
/* 2684 */         usage();
/* 2685 */         return;
/*      */       }
/*      */       
/* 2688 */       i++;
/*      */     }
/*      */     
/* 2691 */     if ((!applyDefault) && (!verbose)) {
/* 2692 */       console.println("arg -e is invalid unless -v is also specified");
/* 2693 */       usage(); return;
/*      */     }
/*      */     
/*      */     List<Server> servers;
/*      */     List<Server> servers;
/* 2698 */     if ((this.prov instanceof SoapProvisioning)) {
/* 2699 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 2700 */       servers = soapProv.getAllServers(service, applyDefault);
/*      */     } else {
/* 2702 */       servers = this.prov.getAllServers(service);
/*      */     }
/* 2704 */     for (Server server : servers) {
/* 2705 */       if (verbose) {
/* 2706 */         dumpServer(server, applyDefault, null);
/*      */       } else {
/* 2708 */         console.println(server.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllAlwaysOnClusters(String[] args) throws ServiceException {
/* 2714 */     boolean verbose = false;
/*      */     
/* 2716 */     int i = 1;
/* 2717 */     while (i < args.length) {
/* 2718 */       String arg = args[i];
/* 2719 */       if (arg.equals("-v")) {
/* 2720 */         verbose = true;
/*      */       }
/* 2722 */       i++;
/*      */     }
/*      */     List<AlwaysOnCluster> clusters;
/*      */     List<AlwaysOnCluster> clusters;
/* 2726 */     if ((this.prov instanceof SoapProvisioning)) {
/* 2727 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 2728 */       clusters = soapProv.getAllAlwaysOnClusters();
/*      */     } else {
/* 2730 */       clusters = this.prov.getAllAlwaysOnClusters();
/*      */     }
/* 2732 */     for (AlwaysOnCluster cluster : clusters) {
/* 2733 */       if (verbose) {
/* 2734 */         dumpAlwaysOnCluster(cluster, null);
/*      */       } else {
/* 2736 */         console.println(cluster.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllActiveServers(String[] args) throws ServiceException {
/* 2742 */     boolean verbose = false;
/*      */     
/* 2744 */     int i = 1;
/* 2745 */     while (i < args.length) {
/* 2746 */       String arg = args[i];
/* 2747 */       if (arg.equals("-v")) {
/* 2748 */         verbose = true;
/*      */       }
/* 2750 */       i++;
/*      */     }
/*      */     
/* 2753 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 2754 */       throwSoapOnly();
/*      */     }
/*      */     
/* 2757 */     List<Server> servers = ((SoapProvisioning)this.prov).getAllActiveServers();
/* 2758 */     for (Server server : servers) {
/* 2759 */       if (verbose) {
/* 2760 */         dumpServer(server, true, null);
/*      */       } else {
/* 2762 */         console.println(server.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllUCServices(String[] args) throws ServiceException {
/* 2768 */     boolean verbose = (args.length > 1) && (args[1].equals("-v"));
/* 2769 */     Set<String> attrNames = getArgNameSet(args, verbose ? 2 : 1);
/* 2770 */     List<UCService> allUCServices = this.prov.getAllUCServices();
/* 2771 */     for (UCService ucService : allUCServices) {
/* 2772 */       if (verbose) {
/* 2773 */         dumpUCService(ucService, attrNames);
/*      */       } else {
/* 2775 */         console.println(ucService.getName());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpServer(Server server, boolean expandConfig, Set<String> attrNames) throws ServiceException {
/* 2781 */     console.println("# name " + server.getName());
/* 2782 */     Map<String, Object> attrs = server.getAttrs(expandConfig);
/* 2783 */     dumpAttrs(attrs, attrNames);
/* 2784 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpAlwaysOnCluster(AlwaysOnCluster cluster, Set<String> attrNames) throws ServiceException {
/* 2788 */     console.println("# name " + cluster.getName());
/* 2789 */     Map<String, Object> attrs = cluster.getAttrs();
/* 2790 */     dumpAttrs(attrs, attrNames);
/* 2791 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpUCService(UCService ucService, Set<String> attrNames) throws ServiceException {
/* 2795 */     console.println("# name " + ucService.getName());
/* 2796 */     Map<String, Object> attrs = ucService.getAttrs();
/* 2797 */     dumpAttrs(attrs, attrNames);
/* 2798 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpXMPPComponent(XMPPComponent comp, Set<String> attrNames) throws ServiceException {
/* 2802 */     console.println("# name " + comp.getName());
/* 2803 */     Map<String, Object> attrs = comp.getAttrs();
/* 2804 */     dumpAttrs(attrs, attrNames);
/* 2805 */     console.println();
/*      */   }
/*      */   
/*      */   private void doGetAllXMPPComponents() throws ServiceException {
/* 2809 */     List<XMPPComponent> components = this.prov.getAllXMPPComponents();
/* 2810 */     for (XMPPComponent comp : components) {
/* 2811 */       dumpXMPPComponent(comp, null);
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpAccount(Account account, boolean expandCos, Set<String> attrNames) throws ServiceException {
/* 2816 */     console.println("# name " + account.getName());
/* 2817 */     Map<String, Object> attrs = account.getAttrs(expandCos);
/* 2818 */     dumpAttrs(attrs, attrNames);
/* 2819 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpCalendarResource(CalendarResource resource, boolean expandCos, Set<String> attrNames) throws ServiceException {
/* 2823 */     console.println("# name " + resource.getName());
/* 2824 */     Map<String, Object> attrs = resource.getAttrs(expandCos);
/* 2825 */     dumpAttrs(attrs, attrNames);
/* 2826 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpContact(GalContact contact) throws ServiceException {
/* 2830 */     console.println("# name " + contact.getId());
/* 2831 */     Map<String, Object> attrs = contact.getAttrs();
/* 2832 */     dumpAttrs(attrs, null);
/* 2833 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpIdentity(Identity identity, Set<String> attrNameSet) throws ServiceException {
/* 2837 */     console.println("# name " + identity.getName());
/* 2838 */     Map<String, Object> attrs = identity.getAttrs();
/* 2839 */     dumpAttrs(attrs, attrNameSet);
/* 2840 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpSignature(Signature signature, Set<String> attrNameSet) throws ServiceException {
/* 2844 */     console.println("# name " + signature.getName());
/* 2845 */     Map<String, Object> attrs = signature.getAttrs();
/* 2846 */     dumpAttrs(attrs, attrNameSet);
/* 2847 */     console.println();
/*      */   }
/*      */   
/*      */   private void dumpAttrs(Map<String, Object> attrsIn, Set<String> specificAttrs) throws ServiceException {
/* 2851 */     TreeMap<String, Object> attrs = new TreeMap(attrsIn);
/*      */     
/* 2853 */     Map<String, Set<String>> specificAttrValues = null;
/*      */     
/* 2855 */     if (specificAttrs != null) {
/* 2856 */       specificAttrValues = new HashMap();
/* 2857 */       for (String specificAttr : specificAttrs) {
/* 2858 */         int colonAt = specificAttr.indexOf("=");
/* 2859 */         String attrName = null;
/* 2860 */         String attrValue = null;
/* 2861 */         if (colonAt == -1) {
/* 2862 */           attrName = specificAttr;
/*      */         } else {
/* 2864 */           attrName = specificAttr.substring(0, colonAt);
/* 2865 */           attrValue = specificAttr.substring(colonAt + 1);
/* 2866 */           if (attrValue.length() < 1) {
/* 2867 */             throw ServiceException.INVALID_REQUEST("missing value for " + specificAttr, null);
/*      */           }
/*      */         }
/*      */         
/* 2871 */         attrName = attrName.toLowerCase();
/* 2872 */         Set<String> values = (Set)specificAttrValues.get(attrName);
/* 2873 */         if (values == null) {
/* 2874 */           values = new HashSet();
/*      */         }
/* 2876 */         if (attrValue != null) {
/* 2877 */           values.add(attrValue);
/*      */         }
/* 2879 */         specificAttrValues.put(attrName, values);
/*      */       }
/*      */     }
/*      */     
/* 2883 */     AttributeManager attrMgr = AttributeManager.getInstance();
/*      */     
/* 2885 */     SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMddHHmmss");
/* 2886 */     String timestamp = dateFmt.format(new Date());
/*      */     
/* 2888 */     for (Map.Entry<String, Object> entry : attrs.entrySet()) {
/* 2889 */       String name = (String)entry.getKey();
/*      */       
/* 2891 */       boolean isBinary = needsBinaryIO(attrMgr, name);
/*      */       
/* 2893 */       Set<String> specificValues = null;
/* 2894 */       if (specificAttrValues != null) {
/* 2895 */         specificValues = (Set)specificAttrValues.get(name.toLowerCase());
/*      */       }
/* 2897 */       if ((specificAttrValues == null) || (specificAttrValues.keySet().contains(name.toLowerCase())))
/*      */       {
/* 2899 */         Object value = entry.getValue();
/*      */         
/* 2901 */         if ((value instanceof String[])) {
/* 2902 */           String[] sv = (String[])value;
/* 2903 */           for (int i = 0; i < sv.length; i++) {
/* 2904 */             String aSv = sv[i];
/*      */             
/* 2906 */             if ((this.forceDisplayAttrValue) || ((aSv.length() > 0) && ((specificValues == null) || (specificValues.isEmpty()) || (specificValues.contains(aSv))))) {
/* 2907 */               printAttr(name, aSv, Integer.valueOf(i), isBinary, timestamp);
/*      */             }
/*      */           }
/* 2910 */         } else if ((value instanceof String))
/*      */         {
/* 2912 */           if ((this.forceDisplayAttrValue) || ((((String)value).length() > 0) && ((specificValues == null) || (specificValues.isEmpty()) || (specificValues.contains(value))))) {
/* 2913 */             printAttr(name, (String)value, null, isBinary, timestamp);
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*      */ 
/* 2920 */     if (this.forceDisplayAttrValue) {
/* 2921 */       for (String attr : specificAttrs) {
/* 2922 */         if (!attrs.containsKey(attr)) {
/* 2923 */           AttributeInfo ai = attrMgr.getAttributeInfo(attr);
/* 2924 */           if (ai != null) {
/* 2925 */             printAttr(attr, "", null, false, timestamp);
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doCreateDistributionListsBulk(String[] args) throws ServiceException
/*      */   {
/* 2934 */     if (args.length < 3) {
/* 2935 */       usage();
/*      */     } else {
/* 2937 */       String domain = args[1];
/* 2938 */       String nameMask = args[2];
/* 2939 */       int numAccounts = Integer.parseInt(args[3]);
/* 2940 */       for (int i = 0; i < numAccounts; i++) {
/* 2941 */         String name = nameMask + Integer.toString(i) + "@" + domain;
/* 2942 */         Map<String, Object> attrs = new HashMap();
/* 2943 */         String displayName = nameMask + " N. " + Integer.toString(i);
/* 2944 */         StringUtil.addToMultiMap(attrs, "displayName", displayName);
/* 2945 */         DistributionList dl = this.prov.createDistributionList(name, attrs);
/* 2946 */         console.println(dl.getId());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllDistributionLists(String[] args) throws ServiceException {
/* 2952 */     String d = null;
/* 2953 */     boolean verbose = false;
/* 2954 */     int i = 1;
/* 2955 */     while (i < args.length) {
/* 2956 */       String arg = args[i];
/* 2957 */       if (arg.equals("-v")) {
/* 2958 */         verbose = true;
/*      */       }
/* 2960 */       else if (d == null) {
/* 2961 */         d = arg;
/*      */       } else {
/* 2963 */         console.println("invalid arg: " + arg + ", already specified domain: " + d);
/* 2964 */         usage();
/* 2965 */         return;
/*      */       }
/*      */       
/* 2968 */       i++;
/*      */     }
/*      */     
/* 2971 */     if (d == null) {
/* 2972 */       List<Domain> domains = this.prov.getAllDomains();
/* 2973 */       for (Domain domain : domains) {
/* 2974 */         Collection<?> dls = this.prov.getAllGroups(domain);
/* 2975 */         for (Object obj : dls) {
/* 2976 */           Group dl = (Group)obj;
/* 2977 */           if (verbose) {
/* 2978 */             dumpGroup(dl, null);
/*      */           } else {
/* 2980 */             console.println(dl.getName());
/*      */           }
/*      */         }
/*      */       }
/*      */     } else {
/* 2985 */       Domain domain = lookupDomain(d);
/* 2986 */       Collection<?> dls = this.prov.getAllGroups(domain);
/* 2987 */       for (Object obj : dls) {
/* 2988 */         Group dl = (Group)obj;
/* 2989 */         if (verbose) {
/* 2990 */           dumpGroup(dl, null);
/*      */         } else {
/* 2992 */           console.println(dl.getName());
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllCalendarResources(String[] args) throws ServiceException {
/* 2999 */     boolean verbose = false;
/* 3000 */     boolean applyDefault = true;
/* 3001 */     String d = null;
/* 3002 */     String s = null;
/*      */     
/* 3004 */     int i = 1;
/* 3005 */     while (i < args.length) {
/* 3006 */       String arg = args[i];
/* 3007 */       if (arg.equals("-v")) {
/* 3008 */         verbose = true;
/* 3009 */       } else if (arg.equals("-e")) {
/* 3010 */         applyDefault = false;
/* 3011 */       } else if (arg.equals("-s")) {
/* 3012 */         i++;
/* 3013 */         if (i < args.length) {
/* 3014 */           if (s == null) {
/* 3015 */             s = args[i];
/*      */           } else {
/* 3017 */             console.println("invalid arg: " + args[i] + ", already specified -s with " + s);
/* 3018 */             usage();
/*      */           }
/*      */         }
/*      */         else {
/* 3022 */           usage();
/*      */         }
/*      */         
/*      */       }
/* 3026 */       else if (d == null) {
/* 3027 */         d = arg;
/*      */       } else {
/* 3029 */         console.println("invalid arg: " + arg + ", already specified domain: " + d);
/* 3030 */         usage();
/* 3031 */         return;
/*      */       }
/*      */       
/* 3034 */       i++;
/*      */     }
/*      */     
/* 3037 */     if ((!applyDefault) && (!verbose)) {
/* 3038 */       console.println("arg -e is invalid unless -v is also specified");
/* 3039 */       usage();
/* 3040 */       return;
/*      */     }
/*      */     
/*      */ 
/* 3044 */     Provisioning prov = Provisioning.getInstance();
/*      */     
/* 3046 */     Server server = null;
/* 3047 */     if (s != null) {
/* 3048 */       server = lookupServer(s);
/*      */     }
/* 3050 */     if (d == null) {
/* 3051 */       List<Domain> domains = prov.getAllDomains();
/* 3052 */       for (Domain domain : domains) {
/* 3053 */         doGetAllCalendarResources(prov, domain, server, verbose, applyDefault);
/*      */       }
/*      */     } else {
/* 3056 */       Domain domain = lookupDomain(d, prov);
/* 3057 */       doGetAllCalendarResources(prov, domain, server, verbose, applyDefault);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllCalendarResources(Provisioning prov, Domain domain, Server server, final boolean verbose, final boolean applyDefault) throws ServiceException
/*      */   {
/* 3063 */     NamedEntry.Visitor visitor = new NamedEntry.Visitor()
/*      */     {
/*      */       public void visit(NamedEntry entry) throws ServiceException
/*      */       {
/* 3067 */         if (verbose) {
/* 3068 */           ProvUtil.this.dumpCalendarResource((CalendarResource)entry, applyDefault, null);
/*      */         } else {
/* 3070 */           ProvUtil.console.println(entry.getName());
/*      */         }
/*      */       }
/* 3073 */     };
/* 3074 */     prov.getAllCalendarResources(domain, server, visitor);
/*      */   }
/*      */   
/*      */   private void doSearchCalendarResources(String[] args) throws ServiceException
/*      */   {
/* 3079 */     boolean verbose = false;
/* 3080 */     int i = 1;
/*      */     
/* 3082 */     if (args.length < i + 1) {
/* 3083 */       usage();
/* 3084 */       return;
/*      */     }
/* 3086 */     if (args[i].equals("-v")) {
/* 3087 */       verbose = true;
/* 3088 */       i++;
/*      */     }
/* 3090 */     if (args.length < i + 1) {
/* 3091 */       usage();
/* 3092 */       return;
/*      */     }
/* 3094 */     Domain d = lookupDomain(args[(i++)]);
/*      */     
/* 3096 */     if ((args.length - i) % 3 != 0) {
/* 3097 */       usage();
/* 3098 */       return;
/*      */     }
/*      */     
/* 3101 */     EntrySearchFilter.Multi multi = new EntrySearchFilter.Multi(false, EntrySearchFilter.AndOr.and);
/* 3102 */     while (i < args.length) {
/* 3103 */       String attr = args[(i++)];
/* 3104 */       String op = args[(i++)];
/* 3105 */       String value = args[(i++)];
/*      */       try {
/* 3107 */         EntrySearchFilter.Single single = new EntrySearchFilter.Single(false, attr, op, value);
/* 3108 */         multi.add(single);
/*      */       } catch (IllegalArgumentException e) {
/* 3110 */         printError("Bad search op in: " + attr + " " + op + " '" + value + "'");
/* 3111 */         e.printStackTrace();
/* 3112 */         usage();
/* 3113 */         return;
/*      */       }
/*      */     }
/* 3116 */     EntrySearchFilter filter = new EntrySearchFilter(multi);
/* 3117 */     String filterStr = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter);
/*      */     
/* 3119 */     SearchDirectoryOptions searchOpts = new SearchDirectoryOptions();
/* 3120 */     searchOpts.setDomain(d);
/* 3121 */     searchOpts.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.resources });
/* 3122 */     searchOpts.setSortOpt(SearchDirectoryOptions.SortOpt.SORT_ASCENDING);
/* 3123 */     searchOpts.setFilterString(ZLdapFilterFactory.FilterId.ADMIN_SEARCH, filterStr);
/*      */     
/* 3125 */     List<NamedEntry> resources = this.prov.searchDirectory(searchOpts);
/*      */     
/*      */ 
/* 3128 */     for (NamedEntry entry : resources) {
/* 3129 */       CalendarResource resource = (CalendarResource)entry;
/* 3130 */       if (verbose) {
/* 3131 */         dumpCalendarResource(resource, true, null);
/*      */       } else
/* 3133 */         console.println(resource.getName());
/*      */     }
/*      */   }
/*      */   
/*      */   private Account lookupAccount(String key, boolean mustFind, boolean applyDefault) throws ServiceException {
/*      */     Account account;
/*      */     Account account;
/* 3140 */     if ((applyDefault == true) || ((this.prov instanceof LdapProv))) {
/* 3141 */       account = this.prov.getAccount(key);
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     }
/*      */     else
/*      */     {
/*      */ 
/*      */ 
/*      */ 
/* 3152 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 3153 */       account = soapProv.getAccount(key, applyDefault);
/*      */     }
/*      */     
/* 3156 */     if ((mustFind) && (account == null)) {
/* 3157 */       throw AccountServiceException.NO_SUCH_ACCOUNT(key);
/*      */     }
/* 3159 */     return account;
/*      */   }
/*      */   
/*      */   private Account lookupAccount(String key) throws ServiceException
/*      */   {
/* 3164 */     return lookupAccount(key, true, true);
/*      */   }
/*      */   
/*      */   private Account lookupAccount(String key, boolean mustFind) throws ServiceException {
/* 3168 */     return lookupAccount(key, mustFind, true);
/*      */   }
/*      */   
/*      */   private CalendarResource lookupCalendarResource(String key) throws ServiceException {
/* 3172 */     CalendarResource res = this.prov.get(guessCalendarResourceBy(key), key);
/* 3173 */     if (res == null) {
/* 3174 */       throw AccountServiceException.NO_SUCH_CALENDAR_RESOURCE(key);
/*      */     }
/* 3176 */     return res;
/*      */   }
/*      */   
/*      */   private Domain lookupDomain(String key) throws ServiceException
/*      */   {
/* 3181 */     return lookupDomain(key, this.prov);
/*      */   }
/*      */   
/*      */ 
/* 3185 */   private Domain lookupDomain(String key, Provisioning prov) throws ServiceException { return lookupDomain(key, prov, true); }
/*      */   
/*      */   private Domain lookupDomain(String key, Provisioning prov, boolean applyDefault) throws ServiceException {
/*      */     Domain domain;
/*      */     Domain domain;
/* 3190 */     if ((prov instanceof SoapProvisioning)) {
/* 3191 */       SoapProvisioning soapProv = (SoapProvisioning)prov;
/* 3192 */       domain = soapProv.get(guessDomainBy(key), key, applyDefault);
/*      */     } else {
/* 3194 */       domain = prov.get(guessDomainBy(key), key);
/*      */     }
/* 3196 */     if (domain == null) {
/* 3197 */       throw AccountServiceException.NO_SUCH_DOMAIN(key);
/*      */     }
/* 3199 */     return domain;
/*      */   }
/*      */   
/*      */   private Cos lookupCos(String key) throws ServiceException
/*      */   {
/* 3204 */     Cos cos = this.prov.get(guessCosBy(key), key);
/* 3205 */     if (cos == null) {
/* 3206 */       throw AccountServiceException.NO_SUCH_COS(key);
/*      */     }
/* 3208 */     return cos;
/*      */   }
/*      */   
/*      */   private Right lookupRight(String rightName) throws ServiceException
/*      */   {
/* 3213 */     return this.prov.getRight(rightName, false);
/*      */   }
/*      */   
/*      */ 
/* 3217 */   private Server lookupServer(String key) throws ServiceException { return lookupServer(key, true); }
/*      */   
/*      */   private Server lookupServer(String key, boolean applyDefault) throws ServiceException {
/*      */     Server server;
/*      */     Server server;
/* 3222 */     if ((this.prov instanceof SoapProvisioning)) {
/* 3223 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 3224 */       server = soapProv.get(guessServerBy(key), key, applyDefault);
/*      */     } else {
/* 3226 */       server = this.prov.get(guessServerBy(key), key);
/*      */     }
/* 3228 */     if (server == null) {
/* 3229 */       throw AccountServiceException.NO_SUCH_SERVER(key);
/*      */     }
/* 3231 */     return server;
/*      */   }
/*      */   
/*      */   private AlwaysOnCluster lookupAlwaysOnCluster(String key) throws ServiceException {
/*      */     AlwaysOnCluster cluster;
/*      */     AlwaysOnCluster cluster;
/* 3237 */     if ((this.prov instanceof SoapProvisioning)) {
/* 3238 */       SoapProvisioning soapProv = (SoapProvisioning)this.prov;
/* 3239 */       cluster = soapProv.get(guessAlwaysOnClusterBy(key), key);
/*      */     } else {
/* 3241 */       cluster = this.prov.get(guessAlwaysOnClusterBy(key), key);
/*      */     }
/* 3243 */     if (cluster == null) {
/* 3244 */       throw AccountServiceException.NO_SUCH_ALWAYSONCLUSTER(key);
/*      */     }
/* 3246 */     return cluster;
/*      */   }
/*      */   
/*      */   private UCService lookupUCService(String key) throws ServiceException
/*      */   {
/* 3251 */     UCService ucService = this.prov.get(guessUCServiceBy(key), key);
/* 3252 */     if (ucService == null) {
/* 3253 */       throw AccountServiceException.NO_SUCH_UC_SERVICE(key);
/*      */     }
/* 3255 */     return ucService;
/*      */   }
/*      */   
/*      */   private String lookupDataSourceId(Account account, String key) throws ServiceException
/*      */   {
/* 3260 */     if (Provisioning.isUUID(key)) {
/* 3261 */       return key;
/*      */     }
/* 3263 */     DataSource ds = this.prov.get(account, Key.DataSourceBy.name, key);
/* 3264 */     if (ds == null) {
/* 3265 */       throw AccountServiceException.NO_SUCH_DATA_SOURCE(key);
/*      */     }
/* 3267 */     return ds.getId();
/*      */   }
/*      */   
/*      */   private String lookupSignatureId(Account account, String key) throws ServiceException
/*      */   {
/* 3272 */     Signature sig = this.prov.get(account, guessSignatureBy(key), key);
/* 3273 */     if (sig == null) {
/* 3274 */       throw AccountServiceException.NO_SUCH_SIGNATURE(key);
/*      */     }
/* 3276 */     return sig.getId();
/*      */   }
/*      */   
/*      */   private DistributionList lookupDistributionList(String key, boolean mustFind) throws ServiceException
/*      */   {
/* 3281 */     DistributionList dl = this.prov.get(guessDistributionListBy(key), key);
/* 3282 */     if ((mustFind) && (dl == null)) {
/* 3283 */       throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(key);
/*      */     }
/* 3285 */     return dl;
/*      */   }
/*      */   
/*      */   private DistributionList lookupDistributionList(String key) throws ServiceException
/*      */   {
/* 3290 */     return lookupDistributionList(key, true);
/*      */   }
/*      */   
/*      */   private Group lookupGroup(String key, boolean mustFind) throws ServiceException {
/* 3294 */     Group dl = this.prov.getGroup(guessDistributionListBy(key), key);
/* 3295 */     if ((mustFind) && (dl == null)) {
/* 3296 */       throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(key);
/*      */     }
/* 3298 */     return dl;
/*      */   }
/*      */   
/*      */   private Group lookupGroup(String key) throws ServiceException
/*      */   {
/* 3303 */     return lookupGroup(key, true);
/*      */   }
/*      */   
/*      */   private XMPPComponent lookupXMPPComponent(String value) throws ServiceException {
/* 3307 */     if (Provisioning.isUUID(value)) {
/* 3308 */       return this.prov.get(Key.XMPPComponentBy.id, value);
/*      */     }
/* 3310 */     return this.prov.get(Key.XMPPComponentBy.name, value);
/*      */   }
/*      */   
/*      */   public static Key.AccountBy guessAccountBy(String value)
/*      */   {
/* 3315 */     if (Provisioning.isUUID(value)) {
/* 3316 */       return Key.AccountBy.id;
/*      */     }
/* 3318 */     return Key.AccountBy.name;
/*      */   }
/*      */   
/*      */   public static Key.CosBy guessCosBy(String value)
/*      */   {
/* 3323 */     if (Provisioning.isUUID(value)) {
/* 3324 */       return Key.CosBy.id;
/*      */     }
/* 3326 */     return Key.CosBy.name;
/*      */   }
/*      */   
/*      */   public static Key.DomainBy guessDomainBy(String value) {
/* 3330 */     if (Provisioning.isUUID(value)) {
/* 3331 */       return Key.DomainBy.id;
/*      */     }
/* 3333 */     return Key.DomainBy.name;
/*      */   }
/*      */   
/*      */   public static Key.ServerBy guessServerBy(String value) {
/* 3337 */     if (Provisioning.isUUID(value)) {
/* 3338 */       return Key.ServerBy.id;
/*      */     }
/* 3340 */     return Key.ServerBy.name;
/*      */   }
/*      */   
/*      */   public static Key.AlwaysOnClusterBy guessAlwaysOnClusterBy(String value) {
/* 3344 */     if (Provisioning.isUUID(value)) {
/* 3345 */       return Key.AlwaysOnClusterBy.id;
/*      */     }
/* 3347 */     return Key.AlwaysOnClusterBy.name;
/*      */   }
/*      */   
/*      */   public static Key.UCServiceBy guessUCServiceBy(String value) {
/* 3351 */     if (Provisioning.isUUID(value)) {
/* 3352 */       return Key.UCServiceBy.id;
/*      */     }
/* 3354 */     return Key.UCServiceBy.name;
/*      */   }
/*      */   
/*      */   public static Key.CalendarResourceBy guessCalendarResourceBy(String value) {
/* 3358 */     if (Provisioning.isUUID(value)) {
/* 3359 */       return Key.CalendarResourceBy.id;
/*      */     }
/* 3361 */     return Key.CalendarResourceBy.name;
/*      */   }
/*      */   
/*      */   public static Key.DistributionListBy guessDistributionListBy(String value) {
/* 3365 */     if (Provisioning.isUUID(value)) {
/* 3366 */       return Key.DistributionListBy.id;
/*      */     }
/* 3368 */     return Key.DistributionListBy.name;
/*      */   }
/*      */   
/*      */   public static Key.SignatureBy guessSignatureBy(String value) {
/* 3372 */     if (Provisioning.isUUID(value)) {
/* 3373 */       return Key.SignatureBy.id;
/*      */     }
/* 3375 */     return Key.SignatureBy.name;
/*      */   }
/*      */   
/*      */   public static TargetBy guessTargetBy(String value) {
/* 3379 */     if (Provisioning.isUUID(value)) {
/* 3380 */       return TargetBy.id;
/*      */     }
/* 3382 */     return TargetBy.name;
/*      */   }
/*      */   
/*      */   public static GranteeSelector.GranteeBy guessGranteeBy(String value) {
/* 3386 */     if (Provisioning.isUUID(value)) {
/* 3387 */       return GranteeSelector.GranteeBy.id;
/*      */     }
/* 3389 */     return GranteeSelector.GranteeBy.name;
/*      */   }
/*      */   
/*      */   private void checkDeprecatedAttrs(Map<String, ? extends Object> attrs) throws ServiceException {
/* 3393 */     AttributeManager am = AttributeManager.getInstance();
/* 3394 */     boolean hadWarnings = false;
/* 3395 */     for (String attr : attrs.keySet()) {
/* 3396 */       AttributeInfo ai = am.getAttributeInfo(attr);
/* 3397 */       if (ai != null)
/*      */       {
/*      */ 
/*      */ 
/* 3401 */         if (ai.isDeprecated()) {
/* 3402 */           hadWarnings = true;
/* 3403 */           console.println("Warn: attribute " + attr + " has been deprecated since " + ai.getDeprecatedSince());
/*      */         }
/*      */       }
/*      */     }
/* 3407 */     if (hadWarnings) {
/* 3408 */       console.println();
/*      */     }
/*      */   }
/*      */   
/*      */   private static boolean needsBinaryIO(AttributeManager attrMgr, String attr) {
/* 3413 */     return attrMgr.containsBinaryData(attr);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private Map<String, Object> getMapAndCheck(String[] args, int offset, boolean isCreateCmd)
/*      */     throws ProvUtil.ArgException, ServiceException
/*      */   {
/* 3421 */     Map<String, Object> attrs = getAttrMap(args, offset, isCreateCmd);
/* 3422 */     checkDeprecatedAttrs(attrs);
/* 3423 */     return attrs;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private Map<String, Object> keyValueArrayToMultiMap(String[] args, int offset, boolean isCreateCmd)
/*      */     throws IOException, ServiceException
/*      */   {
/* 3443 */     AttributeManager attrMgr = AttributeManager.getInstance();
/*      */     
/* 3445 */     Map<String, Object> attrs = new HashMap();
/*      */     
/* 3447 */     String safeguarded_attrs_prop = LC.get("zmprov_safeguarded_attrs");
/* 3448 */     Set<String> safeguarded_attrs = safeguarded_attrs_prop == null ? Sets.newHashSet() : Sets.newHashSet(safeguarded_attrs_prop.toLowerCase().split(","));
/*      */     
/* 3450 */     Multiset<String> multiValAttrsToCheck = HashMultiset.create();
/*      */     
/* 3452 */     for (int i = offset; i < args.length; i += 2) {
/* 3453 */       String n = args[i];
/* 3454 */       if (i + 1 >= args.length) {
/* 3455 */         throw new IllegalArgumentException("not enough arguments");
/*      */       }
/* 3457 */       String v = args[(i + 1)];
/* 3458 */       String attrName = n;
/* 3459 */       if ((n.charAt(0) == '+') || (n.charAt(0) == '-')) {
/* 3460 */         attrName = attrName.substring(1);
/* 3461 */       } else if ((safeguarded_attrs.contains(attrName.toLowerCase())) && (attrMgr.isMultiValued(attrName))) {
/* 3462 */         multiValAttrsToCheck.add(attrName.toLowerCase());
/*      */       }
/* 3464 */       if ((needsBinaryIO(attrMgr, attrName)) && (v.length() > 0)) {
/* 3465 */         File file = new File(v);
/* 3466 */         byte[] bytes = ByteUtil.getContent(file);
/* 3467 */         v = ByteUtil.encodeLDAPBase64(bytes);
/*      */       }
/* 3469 */       StringUtil.addToMultiMap(attrs, n, v);
/*      */     }
/*      */     
/* 3472 */     if ((!this.allowMultiValuedAttrReplacement) && (!isCreateCmd)) {
/* 3473 */       for (Multiset.Entry<String> entry : multiValAttrsToCheck.entrySet()) {
/* 3474 */         if (entry.getCount() == 1)
/*      */         {
/*      */ 
/* 3477 */           printError("error: cannot replace multi-valued attr value unless -r is specified");
/* 3478 */           System.exit(2);
/*      */         }
/*      */       }
/*      */     }
/*      */     
/* 3483 */     return attrs;
/*      */   }
/*      */   
/*      */   private Map<String, Object> getAttrMap(String[] args, int offset, boolean isCreateCmd) throws ProvUtil.ArgException, ServiceException
/*      */   {
/*      */     try {
/* 3489 */       return keyValueArrayToMultiMap(args, offset, isCreateCmd);
/*      */     } catch (IllegalArgumentException iae) {
/* 3491 */       throw new ArgException("not enough arguments");
/*      */     } catch (IOException ioe) {
/* 3493 */       throw ServiceException.INVALID_REQUEST("unable to process arguments", ioe);
/*      */     }
/*      */   }
/*      */   
/*      */   private Map<String, Object> getMap(String[] args, int offset) throws ProvUtil.ArgException {
/*      */     try {
/* 3499 */       return StringUtil.keyValueArrayToMultiMap(args, offset);
/*      */     } catch (IllegalArgumentException iae) {
/* 3501 */       throw new ArgException("not enough arguments");
/*      */     }
/*      */   }
/*      */   
/*      */   private Set<String> getArgNameSet(String[] args, int offset) {
/* 3506 */     if (offset >= args.length) {
/* 3507 */       return null;
/*      */     }
/* 3509 */     Set<String> result = new HashSet();
/* 3510 */     for (int i = offset; i < args.length; i++) {
/* 3511 */       result.add(args[i].toLowerCase());
/*      */     }
/* 3513 */     return result;
/*      */   }
/*      */   
/*      */   private void interactive(BufferedReader in) throws IOException {
/* 3517 */     this.cliReader = in;
/* 3518 */     this.interactiveMode = true;
/*      */     for (;;) {
/* 3520 */       console.print("prov> ");
/* 3521 */       String line = StringUtil.readLine(in);
/* 3522 */       if (line == null) {
/*      */         break;
/*      */       }
/* 3525 */       if (this.verboseMode) {
/* 3526 */         console.println(line);
/*      */       }
/* 3528 */       String[] args = StringUtil.parseLine(line);
/* 3529 */       if (args.length != 0)
/*      */       {
/*      */         try
/*      */         {
/* 3533 */           if (!execute(args)) {
/* 3534 */             console.println("Unknown command. Type: 'help commands' for a list");
/*      */           }
/*      */         } catch (ServiceException e) {
/* 3537 */           Throwable cause = e.getCause();
/* 3538 */           this.errorOccursDuringInteraction = true;
/* 3539 */           String errText = "ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? "" : new StringBuilder().append(" (cause: ").append(cause.getClass().getName()).append(" ").append(cause.getMessage()).append(")").toString());
/*      */           
/* 3541 */           printError(errText);
/* 3542 */           if (this.verboseMode) {
/* 3543 */             e.printStackTrace(errConsole);
/*      */           }
/*      */         } catch (ArgException e) {
/* 3546 */           usage();
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private void outputBinaryAttrToFile(String attrName, Integer idx, byte[] value, String timestamp)
/*      */     throws ServiceException
/*      */   {
/* 3564 */     StringBuilder sb = new StringBuilder(LC.zmprov_tmp_directory.value());
/* 3565 */     sb.append(File.separator).append(attrName);
/* 3566 */     if (idx != null) {
/* 3567 */       sb.append("_" + idx);
/*      */     }
/* 3569 */     sb.append("_" + timestamp);
/*      */     
/* 3571 */     File file = new File(sb.toString());
/* 3572 */     if (file.exists()) {
/* 3573 */       file.delete();
/*      */     }
/*      */     try
/*      */     {
/* 3577 */       FileUtil.ensureDirExists(file.getParentFile());
/*      */     } catch (IOException e) {
/* 3579 */       throw ServiceException.FAILURE("Unable to create directory " + file.getParentFile().getAbsolutePath(), e);
/*      */     }
/*      */     try
/*      */     {
/* 3583 */       ByteUtil.putContent(file.getAbsolutePath(), value);
/*      */     } catch (IOException e) {
/* 3585 */       throw ServiceException.FAILURE("Unable to write to file " + file.getAbsolutePath(), e);
/*      */     }
/*      */   }
/*      */   
/*      */   private void printAttr(String attrName, String value, Integer idx, boolean isBinary, String timestamp) throws ServiceException
/*      */   {
/* 3591 */     if (isBinary) {
/* 3592 */       byte[] binary = ByteUtil.decodeLDAPBase64(value);
/* 3593 */       if (outputBinaryToFile()) {
/* 3594 */         outputBinaryAttrToFile(attrName, idx, binary, timestamp);
/*      */ 
/*      */       }
/*      */       else
/*      */       {
/* 3599 */         String based64Chunked = new String(Base64.encodeBase64Chunked(binary));
/*      */         
/* 3601 */         if (based64Chunked.charAt(based64Chunked.length() - 1) == '\n') {
/* 3602 */           based64Chunked = based64Chunked.substring(0, based64Chunked.length() - 1);
/*      */         }
/* 3604 */         printOutput(attrName + ":: " + based64Chunked);
/*      */       }
/*      */     } else {
/* 3607 */       printOutput(attrName + ": " + value);
/*      */     }
/*      */   }
/*      */   
/*      */   private static void printError(String text) {
/* 3612 */     PrintStream ps = errConsole;
/*      */     try {
/* 3614 */       BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ps, Charsets.UTF_8));
/* 3615 */       writer.write(text + "\n");
/* 3616 */       writer.flush();
/*      */     } catch (IOException e) {
/* 3618 */       ps.println(text);
/*      */     }
/*      */   }
/*      */   
/*      */   private static void printOutput(String text) {
/* 3623 */     PrintStream ps = console;
/*      */     try {
/* 3625 */       BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ps, Charsets.UTF_8));
/* 3626 */       writer.write(text + "\n");
/* 3627 */       writer.flush();
/*      */     } catch (IOException e) {
/* 3629 */       ps.println(text);
/*      */     }
/*      */   }
/*      */   
/*      */   public static void main(String[] args) throws IOException, ServiceException {
/* 3634 */     CliUtil.setCliSoapHttpTransportTimeout();
/* 3635 */     ZimbraLog.toolSetupLog4jConsole("INFO", true, false);
/* 3636 */     SocketFactories.registerProtocols();
/*      */     
/* 3638 */     SoapTransport.setDefaultUserAgent("zmprov", BuildInfo.VERSION);
/*      */     
/* 3640 */     ProvUtil pu = new ProvUtil();
/* 3641 */     CommandLineParser parser = new PosixParser();
/* 3642 */     Options options = new Options();
/*      */     
/* 3644 */     options.addOption("h", "help", false, "display usage");
/* 3645 */     options.addOption("f", "file", true, "use file as input stream");
/* 3646 */     options.addOption("s", "server", true, "host[:port] of server to connect to");
/* 3647 */     options.addOption("l", "ldap", false, "provision via LDAP");
/* 3648 */     options.addOption("L", "logpropertyfile", true, "log4j property file");
/* 3649 */     options.addOption("a", "account", true, "account name (not used with --ldap)");
/* 3650 */     options.addOption("p", "password", true, "password for account");
/* 3651 */     options.addOption("P", "passfile", true, "filename with password in it");
/* 3652 */     options.addOption("z", "zadmin", false, "use zimbra admin name/password from localconfig for account/password");
/* 3653 */     options.addOption("v", "verbose", false, "verbose mode");
/* 3654 */     options.addOption("d", "debug", false, "debug mode (SOAP request and response payload)");
/* 3655 */     options.addOption("D", "debughigh", false, "debug mode (SOAP req/resp payload and http headers)");
/* 3656 */     options.addOption("m", "master", false, "use LDAP master (has to be used with --ldap)");
/* 3657 */     options.addOption("t", "temp", false, "write binary values to files in temporary directory specified in localconfig key zmprov_tmp_directory");
/* 3658 */     options.addOption("r", "replace", false, "allow replacement of multi-valued attr value");
/* 3659 */     options.addOption("fd", "forcedisplay", false, "force display attr value");
/* 3660 */     options.addOption(SoapCLI.OPT_AUTHTOKEN);
/* 3661 */     options.addOption(SoapCLI.OPT_AUTHTOKENFILE);
/*      */     
/* 3663 */     CommandLine cl = null;
/* 3664 */     boolean err = false;
/*      */     try
/*      */     {
/* 3667 */       cl = parser.parse(options, args, true);
/*      */     } catch (ParseException pe) {
/* 3669 */       printError("error: " + pe.getMessage());
/* 3670 */       err = true;
/*      */     }
/*      */     
/* 3673 */     if ((err) || (cl.hasOption('h'))) {
/* 3674 */       pu.usage();
/*      */     }
/*      */     
/* 3677 */     if ((cl.hasOption('l')) && (cl.hasOption('s'))) {
/* 3678 */       printError("error: cannot specify both -l and -s at the same time");
/* 3679 */       System.exit(2);
/*      */     }
/*      */     
/* 3682 */     pu.setVerbose(cl.hasOption('v'));
/* 3683 */     if (cl.hasOption('l')) {
/* 3684 */       pu.setUseLdap(true, cl.hasOption('m'));
/*      */     }
/*      */     
/* 3687 */     if (cl.hasOption('L')) {
/* 3688 */       if (cl.hasOption('l')) {
/* 3689 */         ZimbraLog.toolSetupLog4j("INFO", cl.getOptionValue('L'));
/*      */       } else {
/* 3691 */         printError("error: cannot specify -L when -l is not specified");
/* 3692 */         System.exit(2);
/*      */       }
/*      */     }
/*      */     
/* 3696 */     if (cl.hasOption('z')) {
/* 3697 */       pu.setAccount(LC.zimbra_ldap_user.value());
/* 3698 */       pu.setPassword(LC.zimbra_ldap_password.value());
/*      */     }
/*      */     
/* 3701 */     if ((cl.hasOption("y")) && (cl.hasOption("Y"))) {
/* 3702 */       printError("error: cannot specify y when Y is specified");
/* 3703 */       System.exit(2);
/*      */     }
/* 3705 */     if (cl.hasOption("y")) {
/* 3706 */       ZAuthToken zat = ZAuthToken.fromJSONString(cl.getOptionValue("y"));
/* 3707 */       pu.setAuthToken(zat);
/*      */     }
/* 3709 */     if (cl.hasOption("Y")) {
/* 3710 */       String authToken = StringUtil.readSingleLineFromFile(cl.getOptionValue("Y"));
/* 3711 */       ZAuthToken zat = ZAuthToken.fromJSONString(authToken);
/* 3712 */       pu.setAuthToken(zat);
/*      */     }
/*      */     
/* 3715 */     if (cl.hasOption('s')) {
/* 3716 */       pu.setServer(cl.getOptionValue('s'));
/*      */     }
/* 3718 */     if (cl.hasOption('a')) {
/* 3719 */       pu.setAccount(cl.getOptionValue('a'));
/*      */     }
/* 3721 */     if (cl.hasOption('p')) {
/* 3722 */       pu.setPassword(cl.getOptionValue('p'));
/*      */     }
/* 3724 */     if (cl.hasOption('P')) {
/* 3725 */       pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
/*      */     }
/*      */     
/* 3728 */     if ((cl.hasOption('d')) && (cl.hasOption('D'))) {
/* 3729 */       printError("error: cannot specify both -d and -D at the same time");
/* 3730 */       System.exit(2);
/*      */     }
/* 3732 */     if (cl.hasOption('D')) {
/* 3733 */       pu.setDebug(SoapDebugLevel.high);
/* 3734 */     } else if (cl.hasOption('d')) {
/* 3735 */       pu.setDebug(SoapDebugLevel.normal);
/*      */     }
/*      */     
/* 3738 */     if ((!pu.useLdap()) && (cl.hasOption('m'))) {
/* 3739 */       printError("error: cannot specify -m when -l is not specified");
/* 3740 */       System.exit(2);
/*      */     }
/*      */     
/* 3743 */     if (cl.hasOption('t')) {
/* 3744 */       pu.setOutputBinaryToFile(true);
/*      */     }
/*      */     
/* 3747 */     if (cl.hasOption('r')) {
/* 3748 */       pu.setAllowMultiValuedAttrReplacement(true);
/*      */     }
/*      */     
/* 3751 */     if (cl.hasOption("fd")) {
/* 3752 */       pu.setForceDisplayAttrValue(true);
/*      */     }
/*      */     
/* 3755 */     args = cl.getArgs();
/*      */     try
/*      */     {
/* 3758 */       if (args.length < 1) {
/* 3759 */         pu.initProvisioning();
/* 3760 */         InputStream is = null;
/* 3761 */         if (cl.hasOption('f')) {
/* 3762 */           pu.setBatchMode(true);
/* 3763 */           is = new FileInputStream(cl.getOptionValue('f'));
/*      */         } else {
/* 3765 */           if (LC.command_line_editing_enabled.booleanValue()) {
/*      */             try {
/* 3767 */               CliUtil.enableCommandLineEditing(LC.zimbra_home.value() + "/.zmprov_history");
/*      */             } catch (IOException e) {
/* 3769 */               errConsole.println("Command line editing will be disabled: " + e);
/* 3770 */               if (pu.verboseMode) {
/* 3771 */                 e.printStackTrace(errConsole);
/*      */               }
/*      */             }
/*      */           }
/*      */           
/*      */ 
/* 3777 */           is = System.in;
/*      */         }
/* 3779 */         pu.interactive(new BufferedReader(new InputStreamReader(is, "UTF-8")));
/*      */       } else {
/* 3781 */         Command cmd = pu.lookupCommand(args[0]);
/* 3782 */         if (cmd == null) {
/* 3783 */           pu.usage();
/*      */         }
/* 3785 */         if (cmd.isDeprecated()) {
/* 3786 */           pu.deprecated();
/*      */         }
/* 3788 */         if (pu.forceLdapButDontRequireUseLdapOption(cmd)) {
/* 3789 */           pu.setUseLdap(true, false);
/*      */         }
/*      */         
/* 3792 */         if (pu.needProvisioningInstance(cmd)) {
/* 3793 */           pu.initProvisioning();
/*      */         }
/*      */         try
/*      */         {
/* 3797 */           if (!pu.execute(args)) {
/* 3798 */             pu.usage();
/*      */           }
/*      */         } catch (ArgException e) {
/* 3801 */           pu.usage();
/*      */         }
/*      */       }
/*      */     } catch (ServiceException e) {
/* 3805 */       Throwable cause = e.getCause();
/* 3806 */       String errText = "ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? "" : new StringBuilder().append(" (cause: ").append(cause.getClass().getName()).append(" ").append(cause.getMessage()).append(")").toString());
/*      */       
/*      */ 
/* 3809 */       printError(errText);
/*      */       
/* 3811 */       if (pu.verboseMode) {
/* 3812 */         e.printStackTrace(errConsole);
/*      */       }
/* 3814 */       System.exit(2);
/*      */     }
/*      */   }
/*      */   
/*      */   class ArgException
/*      */     extends Exception {
/* 3820 */     ArgException(String msg) { super(); }
/*      */   }
/*      */   
/*      */   private static class DescribeArgs {
/*      */     boolean mNonInheritedOnly;
/*      */     boolean mOnThisObjectTypeOnly;
/*      */     
/* 3827 */     static enum Field { type, 
/* 3828 */       value, 
/* 3829 */       callback, 
/* 3830 */       immutable, 
/* 3831 */       cardinality, 
/* 3832 */       requiredIn, 
/* 3833 */       optionalIn, 
/* 3834 */       flags, 
/* 3835 */       defaults, 
/* 3836 */       min, 
/* 3837 */       max, 
/* 3838 */       id, 
/* 3839 */       requiresRestart, 
/* 3840 */       since, 
/* 3841 */       deprecatedSince;
/*      */       
/*      */       private Field() {}
/* 3844 */       static String formatDefaults(AttributeInfo ai) { StringBuilder sb = new StringBuilder();
/* 3845 */         for (String d : ai.getDefaultCosValues()) {
/* 3846 */           sb.append(d + ",");
/*      */         }
/* 3848 */         for (String d : ai.getGlobalConfigValues()) {
/* 3849 */           sb.append(d + ",");
/*      */         }
/* 3851 */         return sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1);
/*      */       }
/*      */       
/*      */       static String formatRequiredIn(AttributeInfo ai) {
/* 3855 */         Set<AttributeClass> requiredIn = ai.getRequiredIn();
/* 3856 */         if (requiredIn == null) {
/* 3857 */           return "";
/*      */         }
/* 3859 */         StringBuilder sb = new StringBuilder();
/*      */         
/* 3861 */         for (AttributeClass ac : requiredIn) {
/* 3862 */           sb.append(ac.name() + ",");
/*      */         }
/* 3864 */         return sb.substring(0, sb.length() - 1);
/*      */       }
/*      */       
/*      */       static String formatOptionalIn(AttributeInfo ai) {
/* 3868 */         Set<AttributeClass> optionalIn = ai.getOptionalIn();
/* 3869 */         if (optionalIn == null) {
/* 3870 */           return "";
/*      */         }
/* 3872 */         StringBuilder sb = new StringBuilder();
/* 3873 */         for (AttributeClass ac : optionalIn) {
/* 3874 */           sb.append(ac.name() + ",");
/*      */         }
/* 3876 */         return sb.substring(0, sb.length() - 1);
/*      */       }
/*      */       
/*      */       static String formatFlags(AttributeInfo ai) {
/* 3880 */         StringBuilder sb = new StringBuilder();
/* 3881 */         for (AttributeFlag f : AttributeFlag.values()) {
/* 3882 */           if (ai.hasFlag(f)) {
/* 3883 */             sb.append(f.name() + ",");
/*      */           }
/*      */         }
/* 3886 */         return sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1);
/*      */       }
/*      */       
/*      */       static String formatRequiresRestart(AttributeInfo ai) {
/* 3890 */         StringBuilder sb = new StringBuilder();
/* 3891 */         List<AttributeServerType> requiresRetstart = ai.getRequiresRestart();
/* 3892 */         if (requiresRetstart != null) {
/* 3893 */           for (AttributeServerType ast : requiresRetstart) {
/* 3894 */             sb.append(ast.name() + ",");
/*      */           }
/*      */         }
/* 3897 */         return sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1);
/*      */       }
/*      */       
/*      */       static String print(Field field, AttributeInfo ai) {
/* 3901 */         String out = null;
/*      */         
/* 3903 */         switch (ProvUtil.7.$SwitchMap$com$zimbra$cs$account$ProvUtil$DescribeArgs$Field[field.ordinal()]) {
/*      */         case 1: 
/* 3905 */           out = ai.getType().getName();
/* 3906 */           break;
/*      */         case 2: 
/* 3908 */           out = ai.getValue();
/* 3909 */           break;
/*      */         case 3: 
/* 3911 */           AttributeCallback acb = ai.getCallback();
/* 3912 */           if (acb != null) {
/* 3913 */             out = acb.getClass().getSimpleName();
/*      */           }
/*      */           break;
/*      */         case 4: 
/* 3917 */           out = Boolean.toString(ai.isImmutable());
/* 3918 */           break;
/*      */         case 5: 
/* 3920 */           AttributeCardinality card = ai.getCardinality();
/* 3921 */           if (card != null) {
/* 3922 */             out = card.name();
/*      */           }
/*      */           break;
/*      */         case 6: 
/* 3926 */           out = formatRequiredIn(ai);
/* 3927 */           break;
/*      */         case 7: 
/* 3929 */           out = formatOptionalIn(ai);
/* 3930 */           break;
/*      */         case 8: 
/* 3932 */           out = formatFlags(ai);
/* 3933 */           break;
/*      */         case 9: 
/* 3935 */           out = formatDefaults(ai);
/* 3936 */           break;
/*      */         case 10: 
/* 3938 */           long min = ai.getMin();
/* 3939 */           if ((min != Long.MIN_VALUE) && (min != -2147483648L)) {
/* 3940 */             out = Long.toString(min);
/*      */           }
/*      */           break;
/*      */         case 11: 
/* 3944 */           long max = ai.getMax();
/* 3945 */           if ((max != Long.MAX_VALUE) && (max != 2147483647L)) {
/* 3946 */             out = Long.toString(max);
/*      */           }
/*      */           break;
/*      */         case 12: 
/* 3950 */           int id = ai.getId();
/* 3951 */           if (id != -1) {
/* 3952 */             out = Integer.toString(ai.getId());
/*      */           }
/*      */           break;
/*      */         case 13: 
/* 3956 */           out = formatRequiresRestart(ai);
/* 3957 */           break;
/*      */         case 14: 
/* 3959 */           List<Version> since = ai.getSince();
/* 3960 */           if (since != null) {
/* 3961 */             StringBuilder sb = new StringBuilder();
/* 3962 */             for (Version version : since) {
/* 3963 */               sb.append(version.toString()).append(",");
/*      */             }
/* 3965 */             sb.setLength(sb.length() - 1);
/* 3966 */             out = sb.toString(); }
/* 3967 */           break;
/*      */         
/*      */         case 15: 
/* 3970 */           Version depreSince = ai.getDeprecatedSince();
/* 3971 */           if (depreSince != null) {
/* 3972 */             out = depreSince.toString();
/*      */           }
/*      */           break;
/*      */         }
/*      */         
/* 3977 */         if (out == null) {
/* 3978 */           out = "";
/*      */         }
/* 3980 */         return out;
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */     AttributeClass mAttrClass;
/*      */     
/*      */ 
/*      */     boolean mVerbose;
/*      */     
/*      */ 
/*      */     String mAttr;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   static String formatLine(int width)
/*      */   {
/* 4000 */     StringBuilder sb = new StringBuilder();
/* 4001 */     for (int i = 0; i < width; i++) {
/* 4002 */       sb.append("-");
/*      */     }
/* 4004 */     return sb.toString();
/*      */   }
/*      */   
/*      */   private String formatAllEntryTypes() {
/* 4008 */     StringBuilder sb = new StringBuilder();
/* 4009 */     for (AttributeClass ac : AttributeClass.values()) {
/* 4010 */       if (ac.isProvisionable()) {
/* 4011 */         sb.append(ac.name() + ",");
/*      */       }
/*      */     }
/* 4014 */     return sb.substring(0, sb.length() - 1);
/*      */   }
/*      */   
/*      */   private void descAttrsUsage(Exception e) {
/* 4018 */     console.println(e.getMessage() + "\n");
/*      */     
/* 4020 */     console.printf("usage:  %s(%s) %s\n", new Object[] { this.command.getName(), this.command.getAlias(), this.command.getHelp() });
/*      */     
/* 4022 */     console.println();
/* 4023 */     console.println("Valid entry types: " + formatAllEntryTypes() + "\n");
/*      */     
/* 4025 */     console.println("Examples:");
/*      */     
/* 4027 */     console.println("zmprov desc");
/* 4028 */     console.println("    print attribute name of all attributes\n");
/*      */     
/* 4030 */     console.println("zmprov desc -v");
/* 4031 */     console.println("    print attribute name and description of all attributes\n");
/*      */     
/* 4033 */     console.println("zmprov desc account");
/* 4034 */     console.println("    print attribute name of all account attributes\n");
/*      */     
/* 4036 */     console.println("zmprov desc -ni -v account");
/* 4037 */     console.println("    print attribute name and description of all non-inherited account attributes, ");
/* 4038 */     console.println("    that is, attributes that are on account but not on cos\n");
/*      */     
/* 4040 */     console.println("zmprov desc -ni domain");
/* 4041 */     console.println("    print attribute name of all non-inherited domain attributes, ");
/* 4042 */     console.println("    that is, attributes that are on domain but not on global config\n");
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 4051 */     console.println("zmprov desc -a zimbraId");
/* 4052 */     console.println("    print attribute name, description, and all properties of attribute zimbraId\n");
/*      */     
/* 4054 */     console.println("zmprov desc account -a zimbraId");
/* 4055 */     console.println("    error: can only specify either an entry type or a specific attribute\n");
/*      */     
/* 4057 */     usage();
/*      */   }
/*      */   
/*      */   private DescribeArgs parseDescribeArgs(String[] args) throws ServiceException
/*      */   {
/* 4062 */     DescribeArgs descArgs = new DescribeArgs(null);
/*      */     
/* 4064 */     int i = 1;
/* 4065 */     while (i < args.length) {
/* 4066 */       if ("-v".equals(args[i])) {
/* 4067 */         if (descArgs.mAttr != null) {
/* 4068 */           throw ServiceException.INVALID_REQUEST("cannot specify -v when -a is specified", null);
/*      */         }
/* 4070 */         descArgs.mVerbose = true;
/* 4071 */       } else if (args[i].startsWith("-ni")) {
/* 4072 */         if (descArgs.mAttr != null) {
/* 4073 */           throw ServiceException.INVALID_REQUEST("cannot specify -ni when -a is specified", null);
/*      */         }
/* 4075 */         descArgs.mNonInheritedOnly = true;
/* 4076 */       } else if (args[i].startsWith("-only")) {
/* 4077 */         if (descArgs.mAttr != null) {
/* 4078 */           throw ServiceException.INVALID_REQUEST("cannot specify -only when -a is specified", null);
/*      */         }
/* 4080 */         descArgs.mOnThisObjectTypeOnly = true;
/* 4081 */       } else if (args[i].startsWith("-a")) {
/* 4082 */         if (descArgs.mAttrClass != null) {
/* 4083 */           throw ServiceException.INVALID_REQUEST("cannot specify -a when entry type is specified", null);
/*      */         }
/* 4085 */         if (descArgs.mAttr != null) {
/* 4086 */           throw ServiceException.INVALID_REQUEST("attribute is already specified as " + descArgs.mAttr, null);
/*      */         }
/* 4088 */         if (args.length <= i + 1) {
/* 4089 */           throw ServiceException.INVALID_REQUEST("not enough args", null);
/*      */         }
/* 4091 */         i++;
/* 4092 */         descArgs.mAttr = args[i];
/*      */       }
/*      */       else {
/* 4095 */         if (descArgs.mAttr != null) {
/* 4096 */           throw ServiceException.INVALID_REQUEST("too many args", null);
/*      */         }
/* 4098 */         if (descArgs.mAttrClass != null) {
/* 4099 */           throw ServiceException.INVALID_REQUEST("entry type is already specified as " + descArgs.mAttrClass, null);
/*      */         }
/* 4101 */         AttributeClass ac = AttributeClass.fromString(args[i]);
/* 4102 */         if ((ac == null) || (!ac.isProvisionable())) {
/* 4103 */           throw ServiceException.INVALID_REQUEST("invalid entry type " + ac.name(), null);
/*      */         }
/* 4105 */         descArgs.mAttrClass = ac;
/*      */       }
/* 4107 */       i++;
/*      */     }
/*      */     
/* 4110 */     if (((descArgs.mNonInheritedOnly == true) || (descArgs.mOnThisObjectTypeOnly == true)) && (descArgs.mAttrClass == null)) {
/* 4111 */       throw ServiceException.INVALID_REQUEST("-ni -only must be specified with an entry type", null);
/*      */     }
/*      */     
/* 4114 */     return descArgs;
/*      */   }
/*      */   
/*      */   private void doDescribe(String[] args) throws ServiceException {
/* 4118 */     DescribeArgs descArgs = null;
/*      */     try {
/* 4120 */       descArgs = parseDescribeArgs(args);
/*      */     } catch (ServiceException e) {
/* 4122 */       descAttrsUsage(e);
/* 4123 */       return;
/*      */     } catch (NumberFormatException e) {
/* 4125 */       descAttrsUsage(e);
/* 4126 */       return;
/*      */     }
/*      */     
/* 4129 */     SortedSet<String> attrs = null;
/* 4130 */     String specificAttr = null;
/*      */     
/* 4132 */     AttributeManager am = AttributeManager.getInstance();
/*      */     
/* 4134 */     if (descArgs.mAttr != null)
/*      */     {
/* 4136 */       specificAttr = descArgs.mAttr;
/* 4137 */     } else if (descArgs.mAttrClass != null)
/*      */     {
/* 4139 */       attrs = new TreeSet(am.getAllAttrsInClass(descArgs.mAttrClass));
/* 4140 */       if (descArgs.mNonInheritedOnly) {
/* 4141 */         Set<String> inheritFrom = null;
/* 4142 */         Set<String> netAttrs = null;
/* 4143 */         switch (descArgs.mAttrClass) {
/*      */         case account: 
/* 4145 */           netAttrs = new HashSet(attrs);
/* 4146 */           inheritFrom = new HashSet(am.getAllAttrsInClass(AttributeClass.cos));
/* 4147 */           netAttrs = SetUtil.subtract(netAttrs, inheritFrom);
/* 4148 */           inheritFrom = new HashSet(am.getAllAttrsInClass(AttributeClass.domain));
/* 4149 */           netAttrs = SetUtil.subtract(netAttrs, inheritFrom);
/* 4150 */           break;
/*      */         case domain: 
/*      */         case server: 
/* 4153 */           netAttrs = new HashSet(attrs);
/* 4154 */           inheritFrom = new HashSet(am.getAllAttrsInClass(AttributeClass.globalConfig));
/* 4155 */           netAttrs = SetUtil.subtract(netAttrs, inheritFrom);
/*      */         }
/*      */         
/*      */         
/* 4159 */         if (netAttrs != null) {
/* 4160 */           attrs = new TreeSet(netAttrs);
/*      */         }
/*      */       }
/*      */       
/* 4164 */       if (descArgs.mOnThisObjectTypeOnly) {
/* 4165 */         TreeSet<String> netAttrs = new TreeSet();
/* 4166 */         for (String attr : attrs) {
/* 4167 */           AttributeInfo ai = am.getAttributeInfo(attr);
/* 4168 */           if (ai != null)
/*      */           {
/*      */ 
/* 4171 */             Set<AttributeClass> requiredIn = ai.getRequiredIn();
/* 4172 */             Set<AttributeClass> optionalIn = ai.getOptionalIn();
/* 4173 */             if (((requiredIn == null) || (requiredIn.size() == 1)) && ((optionalIn == null) || (optionalIn.size() == 1)))
/*      */             {
/* 4175 */               netAttrs.add(attr); }
/*      */           }
/*      */         }
/* 4178 */         attrs = netAttrs;
/*      */ 
/*      */ 
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */     }
/*      */     else
/*      */     {
/*      */ 
/*      */ 
/* 4191 */       attrs = new TreeSet();
/* 4192 */       for (AttributeClass ac : AttributeClass.values()) {
/* 4193 */         attrs.addAll(am.getAllAttrsInClass(ac));
/*      */       }
/*      */     }
/*      */     
/* 4197 */     if (specificAttr != null) {
/* 4198 */       AttributeInfo ai = am.getAttributeInfo(specificAttr);
/* 4199 */       if (ai == null) {
/* 4200 */         console.println("no attribute info for " + specificAttr);
/*      */       } else {
/* 4202 */         console.println(ai.getName());
/*      */         
/* 4204 */         String desc = ai.getDescription();
/* 4205 */         console.println(FileGenUtil.wrapComments(desc == null ? "" : desc, 70, "    "));
/* 4206 */         console.println();
/*      */         
/* 4208 */         for (ProvUtil.DescribeArgs.Field f : ProvUtil.DescribeArgs.Field.values()) {
/* 4209 */           console.format("    %15s : %s\n", new Object[] { f.name(), ProvUtil.DescribeArgs.Field.print(f, ai) });
/*      */         }
/*      */       }
/* 4212 */       console.println();
/*      */     }
/*      */     else {
/* 4215 */       for (String attr : attrs) {
/* 4216 */         AttributeInfo ai = am.getAttributeInfo(attr);
/* 4217 */         if (ai == null) {
/* 4218 */           console.println(attr + " (no attribute info)");
/*      */         }
/*      */         else {
/* 4221 */           String attrName = ai.getName();
/* 4222 */           console.println(attrName);
/* 4223 */           if (descArgs.mVerbose) {
/* 4224 */             String desc = ai.getDescription();
/* 4225 */             console.println(FileGenUtil.wrapComments(desc == null ? "" : desc, 70, "    ") + "\n");
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/* 4232 */   private void doFlushCache(String[] args) throws ServiceException { if (!(this.prov instanceof SoapProvisioning)) {
/* 4233 */       throwSoapOnly();
/*      */     }
/*      */     
/* 4236 */     boolean allServers = false;
/*      */     
/* 4238 */     int argIdx = 1;
/* 4239 */     if (args[argIdx].equals("-a")) {
/* 4240 */       allServers = true;
/* 4241 */       if (args.length > 2) {
/* 4242 */         argIdx++;
/*      */       } else {
/* 4244 */         usage();
/* 4245 */         return;
/*      */       }
/*      */     }
/* 4248 */     String type = args[(argIdx++)];
/*      */     
/* 4250 */     Provisioning.CacheEntry[] entries = null;
/*      */     
/* 4252 */     if (args.length > argIdx) {
/* 4253 */       entries = new Provisioning.CacheEntry[args.length - argIdx];
/* 4254 */       for (int i = argIdx; i < args.length; i++) { Key.CacheEntryBy entryBy;
/*      */         Key.CacheEntryBy entryBy;
/* 4256 */         if (Provisioning.isUUID(args[i])) {
/* 4257 */           entryBy = Key.CacheEntryBy.id;
/*      */         } else {
/* 4259 */           entryBy = Key.CacheEntryBy.name;
/*      */         }
/* 4261 */         entries[(i - argIdx)] = new Provisioning.CacheEntry(entryBy, args[i]);
/*      */       }
/*      */     }
/*      */     
/* 4265 */     SoapProvisioning sp = (SoapProvisioning)this.prov;
/* 4266 */     sp.flushCache(type, entries, allServers);
/*      */   }
/*      */   
/*      */   private void doGenerateDomainPreAuthKey(String[] args) throws ServiceException {
/* 4270 */     String key = null;
/* 4271 */     boolean force = false;
/* 4272 */     if (args.length == 3) {
/* 4273 */       if (args[1].equals("-f")) {
/* 4274 */         force = true;
/*      */       } else {
/* 4276 */         usage();
/* 4277 */         return;
/*      */       }
/* 4279 */       key = args[2];
/*      */     } else {
/* 4281 */       key = args[1];
/*      */     }
/*      */     
/* 4284 */     Domain domain = lookupDomain(key);
/* 4285 */     String curPreAuthKey = domain.getAttr("zimbraPreAuthKey");
/* 4286 */     if ((curPreAuthKey != null) && (!force)) {
/* 4287 */       throw ServiceException.INVALID_REQUEST("pre auth key exists for domain " + key + ", use command -f option to force overwriting the existing key", null);
/*      */     }
/*      */     
/* 4290 */     String preAuthKey = PreAuthKey.generateRandomPreAuthKey();
/* 4291 */     HashMap<String, String> attrs = new HashMap();
/* 4292 */     attrs.put("zimbraPreAuthKey", preAuthKey);
/* 4293 */     this.prov.modifyAttrs(domain, attrs);
/* 4294 */     console.printf("preAuthKey: %s\n", new Object[] { preAuthKey });
/* 4295 */     if (curPreAuthKey != null) {
/* 4296 */       console.printf("previous preAuthKey: %s\n", new Object[] { curPreAuthKey });
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGenerateDomainPreAuth(String[] args) throws ServiceException {
/* 4301 */     String key = args[1];
/* 4302 */     Domain domain = lookupDomain(key);
/* 4303 */     String preAuthKey = domain.getAttr("zimbraPreAuthKey", null);
/* 4304 */     if (preAuthKey == null) {
/* 4305 */       throw ServiceException.INVALID_REQUEST("domain not configured for preauth", null);
/*      */     }
/* 4307 */     String name = args[2];
/* 4308 */     String by = args[3];
/* 4309 */     long timestamp = Long.parseLong(args[4]);
/* 4310 */     if (timestamp == 0L) {
/* 4311 */       timestamp = System.currentTimeMillis();
/*      */     }
/* 4313 */     long expires = Long.parseLong(args[5]);
/* 4314 */     HashMap<String, String> params = new HashMap();
/* 4315 */     params.put("account", name);
/* 4316 */     params.put("by", by);
/* 4317 */     params.put("timestamp", timestamp + "");
/* 4318 */     params.put("expires", expires + "");
/* 4319 */     if (args.length == 7) {
/* 4320 */       params.put("admin", args[6]);
/*      */     }
/* 4322 */     console.printf("account: %s\nby: %s\ntimestamp: %s\nexpires: %s\npreauth: %s\n", new Object[] { name, by, Long.valueOf(timestamp), Long.valueOf(expires), PreAuthKey.computePreAuth(params, preAuthKey) });
/*      */   }
/*      */   
/*      */   private void doGetAllMtaAuthURLs() throws ServiceException
/*      */   {
/* 4327 */     List<Server> servers = this.prov.getAllServers();
/* 4328 */     for (Server server : servers) {
/* 4329 */       boolean isTarget = server.getBooleanAttr("zimbraMtaAuthTarget", false);
/* 4330 */       if (isTarget) {
/* 4331 */         console.print(URLUtil.getAdminURL(server) + " ");
/*      */       }
/*      */     }
/* 4334 */     console.println();
/*      */   }
/*      */   
/*      */   private void doGetAllReverseProxyURLs() throws ServiceException
/*      */   {
/* 4339 */     String REVERSE_PROXY_PROTO = "";
/* 4340 */     int REVERSE_PROXY_PORT = 7072;
/*      */     
/* 4342 */     String REVERSE_PROXY_PATH = "/service/extension/nginx-lookup";
/*      */     
/* 4344 */     List<Server> servers = this.prov.getAllMailClientServers();
/* 4345 */     for (Server server : servers) {
/* 4346 */       boolean isTarget = server.getBooleanAttr("zimbraReverseProxyLookupTarget", false);
/* 4347 */       if (isTarget) {
/* 4348 */         String serviceName = server.getAttr("zimbraServiceHostname", "");
/* 4349 */         console.print(REVERSE_PROXY_PROTO + serviceName + ":" + REVERSE_PROXY_PORT + REVERSE_PROXY_PATH + " ");
/*      */       }
/*      */     }
/* 4352 */     console.println();
/*      */   }
/*      */   
/*      */   private void doGetAllReverseProxyBackends() throws ServiceException {
/* 4356 */     List<Server> servers = this.prov.getAllServers();
/* 4357 */     boolean atLeastOne = false;
/* 4358 */     for (Server server : servers) {
/* 4359 */       boolean isTarget = server.getBooleanAttr("zimbraReverseProxyLookupTarget", false);
/* 4360 */       if (isTarget)
/*      */       {
/*      */ 
/*      */ 
/*      */ 
/* 4365 */         String mode = server.getAttr("zimbraMailMode", null);
/* 4366 */         if (mode != null)
/*      */         {
/*      */ 
/* 4369 */           Provisioning.MailMode mailMode = Provisioning.MailMode.fromString(mode);
/*      */           
/* 4371 */           boolean isPlain = (mailMode == Provisioning.MailMode.http) || (mailMode == Provisioning.MailMode.mixed) || (mailMode == Provisioning.MailMode.both);
/*      */           
/*      */           int backendPort;
/*      */           
/*      */           int backendPort;
/* 4376 */           if (isPlain) {
/* 4377 */             backendPort = server.getIntAttr("zimbraMailPort", 0);
/*      */           } else {
/* 4379 */             backendPort = server.getIntAttr("zimbraMailSSLPort", 0);
/*      */           }
/*      */           
/* 4382 */           String serviceName = server.getAttr("zimbraServiceHostname", "");
/* 4383 */           console.println("    server " + serviceName + ":" + backendPort + ";");
/* 4384 */           atLeastOne = true;
/*      */         }
/*      */       } }
/* 4387 */     if (!atLeastOne)
/*      */     {
/* 4389 */       console.println("    server localhost:8080;");
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllReverseProxyDomains() throws ServiceException
/*      */   {
/* 4395 */     NamedEntry.Visitor visitor = new NamedEntry.Visitor()
/*      */     {
/*      */       public void visit(NamedEntry entry) throws ServiceException {
/* 4398 */         if ((entry.getAttr("zimbraVirtualHostname") != null) && (entry.getAttr("zimbraSSLPrivateKey") != null) && (entry.getAttr("zimbraSSLCertificate") != null))
/*      */         {
/*      */ 
/* 4401 */           StringBuilder virtualHosts = new StringBuilder();
/* 4402 */           for (String vh : entry.getMultiAttr("zimbraVirtualHostname")) {
/* 4403 */             virtualHosts.append(vh + " ");
/*      */           }
/* 4405 */           ProvUtil.console.println(entry.getName() + " " + virtualHosts);
/*      */         }
/*      */         
/*      */       }
/* 4409 */     };
/* 4410 */     this.prov.getAllDomains(visitor, new String[] { "zimbraVirtualHostname", "zimbraSSLPrivateKey", "zimbraSSLCertificate" });
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void doGetAllMemcachedServers()
/*      */     throws ServiceException
/*      */   {
/* 4418 */     List<Server> servers = this.prov.getAllServers("memcached");
/* 4419 */     for (Server server : servers) {
/* 4420 */       console.print(server.getAttr("zimbraServiceHostname", "") + ":" + server.getAttr("zimbraMemcachedBindPort", "") + " ");
/*      */     }
/*      */     
/* 4423 */     console.println();
/*      */   }
/*      */   
/*      */   private List<Pair<String, Integer>> getMailboxServersFromArgs(String[] args) throws ServiceException
/*      */   {
/* 4428 */     List<Pair<String, Integer>> entries = new ArrayList();
/* 4429 */     if ((args.length == 2) && ("all".equalsIgnoreCase(args[1])))
/*      */     {
/* 4431 */       List<Server> servers = this.prov.getAllMailClientServers();
/* 4432 */       for (Server svr : servers) {
/* 4433 */         String host = svr.getAttr("zimbraServiceHostname");
/* 4434 */         int port = (int)svr.getLongAttr("zimbraAdminPort", this.serverPort);
/* 4435 */         Pair<String, Integer> entry = new Pair(host, Integer.valueOf(port));
/* 4436 */         entries.add(entry);
/*      */       }
/*      */     }
/*      */     else {
/* 4440 */       for (int i = 1; i < args.length; i++) {
/* 4441 */         String arg = args[i];
/* 4442 */         if (this.serverHostname.equalsIgnoreCase(arg)) {
/* 4443 */           entries.add(new Pair(this.serverHostname, Integer.valueOf(this.serverPort)));
/*      */         } else {
/* 4445 */           Server svr = this.prov.getServerByServiceHostname(arg);
/* 4446 */           if (svr == null) {
/* 4447 */             throw AccountServiceException.NO_SUCH_SERVER(arg);
/*      */           }
/*      */           
/* 4450 */           int port = (int)svr.getLongAttr("zimbraAdminPort", this.serverPort);
/* 4451 */           entries.add(new Pair(arg, Integer.valueOf(port)));
/*      */         }
/*      */       }
/*      */     }
/* 4455 */     return entries;
/*      */   }
/*      */   
/*      */   private void doReloadMemcachedClientConfig(String[] args) throws ServiceException {
/* 4459 */     List<Pair<String, Integer>> servers = getMailboxServersFromArgs(args);
/*      */     
/* 4461 */     for (Pair<String, Integer> server : servers) {
/* 4462 */       String hostname = (String)server.getFirst();
/* 4463 */       int port = ((Integer)server.getSecond()).intValue();
/* 4464 */       if (this.verboseMode) {
/* 4465 */         console.print("Updating " + hostname + " ... ");
/*      */       }
/* 4467 */       boolean success = false;
/*      */       try {
/* 4469 */         SoapProvisioning sp = new SoapProvisioning();
/* 4470 */         sp.soapSetURI(LC.zimbra_admin_service_scheme.value() + hostname + ":" + port + "/service/admin/soap/");
/* 4471 */         if (this.debugLevel != SoapDebugLevel.none) {
/* 4472 */           sp.soapSetHttpTransportDebugListener(this);
/*      */         }
/* 4474 */         if ((this.account != null) && (this.password != null)) {
/* 4475 */           sp.soapAdminAuthenticate(this.account, this.password);
/* 4476 */         } else if (this.authToken != null) {
/* 4477 */           sp.soapAdminAuthenticate(this.authToken);
/*      */         } else {
/* 4479 */           sp.soapZimbraAdminAuthenticate();
/*      */         }
/* 4481 */         sp.reloadMemcachedClientConfig();
/* 4482 */         success = true;
/*      */       } catch (ServiceException e) {
/* 4484 */         if (this.verboseMode) {
/* 4485 */           console.println("fail");
/* 4486 */           e.printStackTrace(console);
/*      */         } else {
/* 4488 */           console.println("Error updating " + hostname + ": " + e.getMessage());
/*      */         }
/*      */       } finally {
/* 4491 */         if ((this.verboseMode) && (success)) {
/* 4492 */           console.println("ok");
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetMemcachedClientConfig(String[] args) throws ServiceException {
/* 4499 */     List<Pair<String, Integer>> servers = getMailboxServersFromArgs(args);
/*      */     
/* 4501 */     int longestHostname = 0;
/* 4502 */     for (Pair<String, Integer> server : servers) {
/* 4503 */       String hostname = (String)server.getFirst();
/* 4504 */       longestHostname = Math.max(longestHostname, hostname.length());
/*      */     }
/* 4506 */     String hostnameFormat = String.format("%%-%ds", new Object[] { Integer.valueOf(longestHostname) });
/* 4507 */     boolean consistent = true;
/* 4508 */     String prevConf = null;
/* 4509 */     for (Pair<String, Integer> server : servers) {
/* 4510 */       String hostname = (String)server.getFirst();
/* 4511 */       int port = ((Integer)server.getSecond()).intValue();
/*      */       try {
/* 4513 */         SoapProvisioning sp = new SoapProvisioning();
/* 4514 */         sp.soapSetURI(LC.zimbra_admin_service_scheme.value() + hostname + ":" + port + "/service/admin/soap/");
/* 4515 */         if (this.debugLevel != SoapDebugLevel.none) {
/* 4516 */           sp.soapSetHttpTransportDebugListener(this);
/*      */         }
/* 4518 */         if ((this.account != null) && (this.password != null)) {
/* 4519 */           sp.soapAdminAuthenticate(this.account, this.password);
/* 4520 */         } else if (this.authToken != null) {
/* 4521 */           sp.soapAdminAuthenticate(this.authToken);
/*      */         } else {
/* 4523 */           sp.soapZimbraAdminAuthenticate();
/*      */         }
/* 4525 */         SoapProvisioning.MemcachedClientConfig config = sp.getMemcachedClientConfig();
/* 4526 */         String serverList = config.serverList != null ? config.serverList : "none";
/* 4527 */         if (this.verboseMode) {
/* 4528 */           console.printf(hostnameFormat + " => serverList=[%s], hashAlgo=%s, binaryProto=%s, expiry=%ds, timeout=%dms\n", new Object[] { hostname, serverList, config.hashAlgorithm, Boolean.valueOf(config.binaryProtocol), Integer.valueOf(config.defaultExpirySeconds), Long.valueOf(config.defaultTimeoutMillis) });
/*      */ 
/*      */         }
/* 4531 */         else if (config.serverList != null) {
/* 4532 */           if (HashAlgorithm.KETAMA_HASH.toString().equals(config.hashAlgorithm))
/*      */           {
/* 4534 */             console.printf(hostnameFormat + " => %s\n", new Object[] { hostname, serverList });
/*      */           } else {
/* 4536 */             console.printf(hostnameFormat + " => %s (%S)\n", new Object[] { hostname, serverList, config.hashAlgorithm });
/*      */           }
/*      */         } else {
/* 4539 */           console.printf(hostnameFormat + " => none\n", new Object[] { hostname });
/*      */         }
/*      */         
/* 4542 */         String listAndAlgo = serverList + "/" + config.hashAlgorithm;
/* 4543 */         if (prevConf == null) {
/* 4544 */           prevConf = listAndAlgo;
/* 4545 */         } else if (!prevConf.equals(listAndAlgo)) {
/* 4546 */           consistent = false;
/*      */         }
/*      */       } catch (ServiceException e) {
/* 4549 */         console.printf(hostnameFormat + " => ERROR: unable to get configuration\n", new Object[] { hostname });
/* 4550 */         if (this.verboseMode) {
/* 4551 */           e.printStackTrace(console);
/*      */         }
/*      */       }
/*      */     }
/* 4555 */     if (!consistent) {
/* 4556 */       console.println("Inconsistency detected!");
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetServer(String[] args) throws ServiceException {
/* 4561 */     boolean applyDefault = true;
/*      */     
/* 4563 */     int i = 1;
/* 4564 */     while (i < args.length) {
/* 4565 */       String arg = args[i];
/* 4566 */       if (!arg.equals("-e")) break;
/* 4567 */       applyDefault = false;
/*      */       
/*      */ 
/*      */ 
/* 4571 */       i++;
/*      */     }
/* 4573 */     if (i >= args.length) {
/* 4574 */       usage();
/* 4575 */       return;
/*      */     }
/* 4577 */     dumpServer(lookupServer(args[i], applyDefault), applyDefault, getArgNameSet(args, i + 1));
/*      */   }
/*      */   
/*      */   private void doGetAlwaysOnCluster(String[] args) throws ServiceException {
/* 4581 */     dumpAlwaysOnCluster(lookupAlwaysOnCluster(args[1]), getArgNameSet(args, 2));
/*      */   }
/*      */   
/*      */   private void doPurgeAccountCalendarCache(String[] args) throws ServiceException {
/* 4585 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 4586 */       throwSoapOnly();
/*      */     }
/* 4588 */     if (args.length > 1) {
/* 4589 */       for (int i = 1; i < args.length; i++) {
/* 4590 */         Account acct = lookupAccount(args[i], true);
/* 4591 */         this.prov.purgeAccountCalendarCache(acct.getId());
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */   private void doCreateXMPPComponent(String[] args)
/*      */     throws ServiceException, ProvUtil.ArgException
/*      */   {
/* 4600 */     Map<String, Object> map = getMapAndCheck(args, 7, true);
/* 4601 */     map.put("zimbraXMPPComponentClassName", args[4]);
/* 4602 */     map.put("zimbraXMPPComponentCategory", args[5]);
/* 4603 */     map.put("zimbraXMPPComponentType", args[6]);
/* 4604 */     Domain d = lookupDomain(args[2]);
/* 4605 */     String routableName = args[1] + "." + d.getName();
/* 4606 */     console.println(this.prov.createXMPPComponent(routableName, lookupDomain(args[2]), lookupServer(args[3]), map));
/*      */   }
/*      */   
/*      */   private void doGetXMPPComponent(String[] args) throws ServiceException {
/* 4610 */     dumpXMPPComponent(lookupXMPPComponent(args[1]), getArgNameSet(args, 2));
/*      */   }
/*      */   
/*      */   private void doSetServerOffline(String[] args) throws ServiceException {
/* 4614 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 4615 */       throwSoapOnly();
/*      */     }
/* 4617 */     String key = args[1];
/* 4618 */     ((SoapProvisioning)this.prov).setServerOffline(guessServerBy(key), key);
/*      */   }
/*      */   
/*      */   private void doSetLocalServerOnline() throws ServiceException {
/* 4622 */     if (!(this.prov instanceof SoapProvisioning)) {
/* 4623 */       throwSoapOnly();
/*      */     }
/* 4625 */     ((SoapProvisioning)this.prov).setLocalServerOnline();
/*      */   }
/*      */   
/*      */   private static class RightArgs
/*      */   {
/*      */     String mTargetType;
/*      */     String mTargetIdOrName;
/*      */     String mGranteeType;
/*      */     String mGranteeIdOrName;
/*      */     String mSecret;
/*      */     String mRight;
/*      */     RightModifier mRightModifier;
/*      */     String[] mArgs;
/* 4638 */     int mCurPos = 1;
/*      */     
/*      */     RightArgs(String[] args) {
/* 4641 */       this.mArgs = args;
/* 4642 */       this.mCurPos = 1;
/*      */     }
/*      */     
/*      */     String getNextArg() throws ServiceException {
/* 4646 */       if (hasNext()) {
/* 4647 */         return this.mArgs[(this.mCurPos++)];
/*      */       }
/* 4649 */       throw ServiceException.INVALID_REQUEST("not enough arguments", null);
/*      */     }
/*      */     
/*      */     boolean hasNext()
/*      */     {
/* 4654 */       return this.mCurPos < this.mArgs.length;
/*      */     }
/*      */   }
/*      */   
/*      */   private void getRightArgsTarget(RightArgs ra) throws ServiceException, ProvUtil.ArgException {
/* 4659 */     if (ra.mCurPos >= ra.mArgs.length) {
/* 4660 */       throw new ArgException("not enough arguments");
/*      */     }
/* 4662 */     ra.mTargetType = ra.mArgs[(ra.mCurPos++)];
/* 4663 */     TargetType tt = TargetType.fromCode(ra.mTargetType);
/* 4664 */     if (tt.needsTargetIdentity()) {
/* 4665 */       if (ra.mCurPos >= ra.mArgs.length) {
/* 4666 */         throw new ArgException("not enough arguments");
/*      */       }
/* 4668 */       ra.mTargetIdOrName = ra.mArgs[(ra.mCurPos++)];
/*      */     } else {
/* 4670 */       ra.mTargetIdOrName = null;
/*      */     }
/*      */   }
/*      */   
/*      */   private void getRightArgsGrantee(RightArgs ra, boolean needGranteeType, boolean needSecret) throws ServiceException, ProvUtil.ArgException
/*      */   {
/* 4676 */     if (ra.mCurPos >= ra.mArgs.length) {
/* 4677 */       throw new ArgException("not enough arguments");
/*      */     }
/* 4679 */     GranteeType gt = null;
/* 4680 */     if (needGranteeType) {
/* 4681 */       ra.mGranteeType = ra.mArgs[(ra.mCurPos++)];
/* 4682 */       gt = GranteeType.fromCode(ra.mGranteeType);
/*      */     } else {
/* 4684 */       ra.mGranteeType = null;
/*      */     }
/* 4686 */     if ((gt == GranteeType.GT_AUTHUSER) || (gt == GranteeType.GT_PUBLIC)) {
/* 4687 */       return;
/*      */     }
/* 4689 */     if (ra.mCurPos >= ra.mArgs.length) {
/* 4690 */       throw new ArgException("not enough arguments");
/*      */     }
/* 4692 */     ra.mGranteeIdOrName = ra.mArgs[(ra.mCurPos++)];
/*      */     
/* 4694 */     if ((needSecret) && (gt != null) && 
/* 4695 */       (gt.allowSecret())) {
/* 4696 */       if (ra.mCurPos >= ra.mArgs.length) {
/* 4697 */         throw new ArgException("not enough arguments");
/*      */       }
/* 4699 */       ra.mSecret = ra.mArgs[(ra.mCurPos++)];
/*      */     }
/*      */   }
/*      */   
/*      */   private void getRightArgsRight(RightArgs ra) throws ServiceException, ProvUtil.ArgException
/*      */   {
/* 4705 */     if (ra.mCurPos >= ra.mArgs.length) {
/* 4706 */       throw new ArgException("not enough arguments");
/*      */     }
/*      */     
/* 4709 */     ra.mRight = ra.mArgs[(ra.mCurPos++)];
/* 4710 */     ra.mRightModifier = RightModifier.fromChar(ra.mRight.charAt(0));
/* 4711 */     if (ra.mRightModifier != null) {
/* 4712 */       ra.mRight = ra.mRight.substring(1);
/*      */     }
/*      */   }
/*      */   
/*      */   private void getRightArgs(RightArgs ra, boolean needGranteeType, boolean needSecret) throws ServiceException, ProvUtil.ArgException {
/* 4717 */     getRightArgsTarget(ra);
/* 4718 */     getRightArgsGrantee(ra, needGranteeType, needSecret);
/* 4719 */     getRightArgsRight(ra);
/*      */   }
/*      */   
/*      */   private void doCheckRight(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 4723 */     RightArgs ra = new RightArgs(args);
/* 4724 */     getRightArgs(ra, false, false);
/*      */     
/* 4726 */     Map<String, Object> attrs = getMap(args, ra.mCurPos);
/*      */     
/* 4728 */     TargetBy targetBy = ra.mTargetIdOrName == null ? null : guessTargetBy(ra.mTargetIdOrName);
/* 4729 */     GranteeSelector.GranteeBy granteeBy = guessGranteeBy(ra.mGranteeIdOrName);
/*      */     
/* 4731 */     AccessManager.ViaGrant via = new AccessManager.ViaGrant();
/* 4732 */     boolean allow = this.prov.checkRight(ra.mTargetType, targetBy, ra.mTargetIdOrName, granteeBy, ra.mGranteeIdOrName, ra.mRight, attrs, via);
/*      */     
/*      */ 
/* 4735 */     console.println(allow ? "ALLOWED" : "DENIED");
/* 4736 */     if (via.available()) {
/* 4737 */       console.println("Via:");
/* 4738 */       console.println("    target type  : " + via.getTargetType());
/* 4739 */       console.println("    target       : " + via.getTargetName());
/* 4740 */       console.println("    grantee type : " + via.getGranteeType());
/* 4741 */       console.println("    grantee      : " + via.getGranteeName());
/* 4742 */       console.println("    right        : " + (via.isNegativeGrant() ? "DENY " : "") + via.getRight());
/* 4743 */       console.println();
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetAllEffectiveRights(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 4748 */     RightArgs ra = new RightArgs(args);
/*      */     
/* 4750 */     if ((this.prov instanceof LdapProv))
/*      */     {
/* 4752 */       getRightArgsGrantee(ra, true, false);
/*      */ 
/*      */     }
/* 4755 */     else if (ra.mCurPos < args.length) {
/* 4756 */       getRightArgsGrantee(ra, true, false);
/*      */     }
/*      */     
/*      */ 
/* 4760 */     boolean expandSetAttrs = false;
/* 4761 */     boolean expandGetAttrs = false;
/*      */     
/*      */ 
/* 4764 */     for (int i = ra.mCurPos; i < args.length; i++) {
/* 4765 */       if ("expandSetAttrs".equals(args[i])) {
/* 4766 */         expandSetAttrs = true;
/* 4767 */       } else if ("expandGetAttrs".equals(args[i])) {
/* 4768 */         expandGetAttrs = true;
/*      */       } else {
/* 4770 */         throw new ArgException("unrecognized arg: " + args[i]);
/*      */       }
/*      */     }
/*      */     
/* 4774 */     GranteeSelector.GranteeBy granteeBy = ra.mGranteeIdOrName == null ? null : guessGranteeBy(ra.mGranteeIdOrName);
/*      */     
/* 4776 */     RightCommand.AllEffectiveRights allEffRights = this.prov.getAllEffectiveRights(ra.mGranteeType, granteeBy, ra.mGranteeIdOrName, expandSetAttrs, expandGetAttrs);
/*      */     
/*      */ 
/* 4779 */     console.println(allEffRights.granteeType() + " " + allEffRights.granteeName() + "(" + allEffRights.granteeId() + ")" + " has the following rights:");
/*      */     
/*      */ 
/*      */ 
/*      */ 
/* 4784 */     for (Map.Entry<TargetType, RightCommand.RightsByTargetType> rightsByTargetType : allEffRights.rightsByTargetType().entrySet()) {
/* 4785 */       RightCommand.RightsByTargetType rbtt = (RightCommand.RightsByTargetType)rightsByTargetType.getValue();
/* 4786 */       if (!rbtt.hasNoRight()) {
/* 4787 */         dumpRightsByTargetType((TargetType)rightsByTargetType.getKey(), rbtt, expandSetAttrs, expandGetAttrs);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void dumpRightsByTargetType(TargetType targetType, RightCommand.RightsByTargetType rbtt, boolean expandSetAttrs, boolean expandGetAttrs)
/*      */   {
/* 4794 */     console.println("------------------------------------------------------------------");
/* 4795 */     console.println("Target type: " + targetType.getCode());
/* 4796 */     console.println("------------------------------------------------------------------");
/*      */     
/* 4798 */     RightCommand.EffectiveRights er = rbtt.all();
/* 4799 */     if (er != null) {
/* 4800 */       console.println("On all " + targetType.getPrettyName() + " entries");
/* 4801 */       dumpEffectiveRight(er, expandSetAttrs, expandGetAttrs);
/*      */     }
/*      */     
/* 4804 */     if ((rbtt instanceof RightCommand.DomainedRightsByTargetType)) {
/* 4805 */       RightCommand.DomainedRightsByTargetType domainedRights = (RightCommand.DomainedRightsByTargetType)rbtt;
/*      */       
/* 4807 */       for (RightCommand.RightAggregation rightsByDomains : domainedRights.domains()) {
/* 4808 */         dumpRightAggregation(targetType, rightsByDomains, true, expandSetAttrs, expandGetAttrs);
/*      */       }
/*      */     }
/*      */     
/* 4812 */     for (RightCommand.RightAggregation rightsByEntries : rbtt.entries()) {
/* 4813 */       dumpRightAggregation(targetType, rightsByEntries, false, expandSetAttrs, expandGetAttrs);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */   private void dumpRightAggregation(TargetType targetType, RightCommand.RightAggregation rightAggr, boolean domainScope, boolean expandSetAttrs, boolean expandGetAttrs)
/*      */   {
/* 4820 */     Set<String> entries = rightAggr.entries();
/* 4821 */     RightCommand.EffectiveRights er = rightAggr.effectiveRights();
/*      */     
/* 4823 */     for (String entry : entries) {
/* 4824 */       if (domainScope) {
/* 4825 */         console.println("On " + targetType.getCode() + " entries in domain " + entry);
/*      */       } else {
/* 4827 */         console.println("On " + targetType.getCode() + " " + entry);
/*      */       }
/*      */     }
/* 4830 */     dumpEffectiveRight(er, expandSetAttrs, expandGetAttrs);
/*      */   }
/*      */   
/*      */   private void doGetEffectiveRights(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 4834 */     RightArgs ra = new RightArgs(args);
/* 4835 */     getRightArgsTarget(ra);
/*      */     
/* 4837 */     if ((this.prov instanceof LdapProv))
/*      */     {
/* 4839 */       getRightArgsGrantee(ra, false, false);
/*      */ 
/*      */     }
/* 4842 */     else if (ra.mCurPos < args.length) {
/* 4843 */       getRightArgsGrantee(ra, false, false);
/*      */     }
/*      */     
/*      */ 
/* 4847 */     boolean expandSetAttrs = false;
/* 4848 */     boolean expandGetAttrs = false;
/*      */     
/*      */ 
/* 4851 */     for (int i = ra.mCurPos; i < args.length; i++) {
/* 4852 */       if ("expandSetAttrs".equals(args[i])) {
/* 4853 */         expandSetAttrs = true;
/* 4854 */       } else if ("expandGetAttrs".equals(args[i])) {
/* 4855 */         expandGetAttrs = true;
/*      */       } else {
/* 4857 */         throw new ArgException("unrecognized arg: " + args[i]);
/*      */       }
/*      */     }
/*      */     
/* 4861 */     TargetBy targetBy = ra.mTargetIdOrName == null ? null : guessTargetBy(ra.mTargetIdOrName);
/* 4862 */     GranteeSelector.GranteeBy granteeBy = ra.mGranteeIdOrName == null ? null : guessGranteeBy(ra.mGranteeIdOrName);
/*      */     
/* 4864 */     RightCommand.EffectiveRights effRights = this.prov.getEffectiveRights(ra.mTargetType, targetBy, ra.mTargetIdOrName, granteeBy, ra.mGranteeIdOrName, expandSetAttrs, expandGetAttrs);
/*      */     
/*      */ 
/* 4867 */     console.println("Account " + effRights.granteeName() + " has the following rights on target " + effRights.targetType() + " " + effRights.targetName());
/*      */     
/* 4869 */     dumpEffectiveRight(effRights, expandSetAttrs, expandGetAttrs);
/*      */   }
/*      */   
/*      */   private void dumpEffectiveRight(RightCommand.EffectiveRights effRights, boolean expandSetAttrs, boolean expandGetAttrs)
/*      */   {
/* 4874 */     List<String> presetRights = effRights.presetRights();
/* 4875 */     if ((presetRights != null) && (presetRights.size() > 0)) {
/* 4876 */       console.println("================");
/* 4877 */       console.println("Preset rights");
/* 4878 */       console.println("================");
/* 4879 */       for (String r : presetRights) {
/* 4880 */         console.println("    " + r);
/*      */       }
/*      */     }
/*      */     
/* 4884 */     displayAttrs("set", expandSetAttrs, effRights.canSetAllAttrs(), effRights.canSetAttrs());
/* 4885 */     displayAttrs("get", expandGetAttrs, effRights.canGetAllAttrs(), effRights.canGetAttrs());
/*      */     
/* 4887 */     console.println();
/* 4888 */     console.println();
/*      */   }
/*      */   
/*      */   private void displayAttrs(String op, boolean expandAll, boolean allAttrs, SortedMap<String, RightCommand.EffectiveAttr> attrs) {
/* 4892 */     if ((!allAttrs) && (attrs.isEmpty())) {
/* 4893 */       return;
/*      */     }
/* 4895 */     String format = "    %-50s %-30s\n";
/* 4896 */     console.println();
/* 4897 */     console.println("=========================");
/* 4898 */     console.println(op + " attributes rights");
/* 4899 */     console.println("=========================");
/* 4900 */     if (allAttrs)
/* 4901 */       console.println("Can " + op + " all attributes");
/*      */     Iterator i$;
/* 4903 */     if ((!allAttrs) || (expandAll)) {
/* 4904 */       console.println("Can " + op + " the following attributes");
/* 4905 */       console.println("--------------------------------");
/* 4906 */       console.printf(format, new Object[] { "attribute", "default" });
/* 4907 */       console.printf(format, new Object[] { "----------------------------------------", "--------------------" });
/* 4908 */       for (i$ = attrs.values().iterator(); i$.hasNext();) { ea = (RightCommand.EffectiveAttr)i$.next();
/* 4909 */         first = true;
/* 4910 */         if (ea.getDefault().isEmpty()) {
/* 4911 */           console.printf(format, new Object[] { ea.getAttrName(), "" });
/*      */         } else {
/* 4913 */           for (String v : ea.getDefault()) {
/* 4914 */             if (first) {
/* 4915 */               console.printf(format, new Object[] { ea.getAttrName(), v });
/* 4916 */               first = false;
/*      */             } else {
/* 4918 */               console.printf(format, new Object[] { "", v });
/*      */             }
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     RightCommand.EffectiveAttr ea;
/*      */     boolean first;
/*      */   }
/*      */   
/*      */   private void doGetCreateObjectAttrs(String[] args) throws ServiceException
/*      */   {
/* 4930 */     String targetType = args[1];
/*      */     
/* 4932 */     Key.DomainBy domainBy = null;
/* 4933 */     String domain = null;
/* 4934 */     if (!args[2].equals("null")) {
/* 4935 */       domainBy = guessDomainBy(args[2]);
/* 4936 */       domain = args[2];
/*      */     }
/*      */     
/* 4939 */     Key.CosBy cosBy = null;
/* 4940 */     String cos = null;
/* 4941 */     if (!args[3].equals("null")) {
/* 4942 */       cosBy = guessCosBy(args[3]);
/* 4943 */       cos = args[3];
/*      */     }
/*      */     
/* 4946 */     GranteeSelector.GranteeBy granteeBy = null;
/* 4947 */     String grantee = null;
/*      */     
/*      */ 
/*      */ 
/* 4951 */     if ((this.prov instanceof LdapProv)) {
/* 4952 */       granteeBy = guessGranteeBy(args[4]);
/* 4953 */       grantee = args[4];
/*      */     }
/*      */     
/* 4956 */     console.println("Domain:  " + domain);
/* 4957 */     console.println("Cos:     " + cos);
/* 4958 */     console.println("Grantee: " + grantee);
/* 4959 */     console.println();
/*      */     
/* 4961 */     RightCommand.EffectiveRights effRights = this.prov.getCreateObjectAttrs(targetType, domainBy, domain, cosBy, cos, granteeBy, grantee);
/*      */     
/* 4963 */     displayAttrs("set", true, effRights.canSetAllAttrs(), effRights.canSetAttrs());
/*      */   }
/*      */   
/*      */   private void doGetGrants(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 4967 */     RightArgs ra = new RightArgs(args);
/*      */     
/* 4969 */     boolean granteeIncludeGroupsGranteeBelongs = true;
/*      */     
/* 4971 */     while (ra.hasNext()) {
/* 4972 */       String arg = ra.getNextArg();
/* 4973 */       if ("-t".equals(arg)) {
/* 4974 */         getRightArgsTarget(ra);
/* 4975 */       } else if ("-g".equals(arg)) {
/* 4976 */         getRightArgsGrantee(ra, true, false);
/* 4977 */         if (ra.hasNext()) {
/* 4978 */           String includeGroups = ra.getNextArg();
/* 4979 */           if ("1".equals(includeGroups)) {
/* 4980 */             granteeIncludeGroupsGranteeBelongs = true;
/* 4981 */           } else if ("0".equals(includeGroups)) {
/* 4982 */             granteeIncludeGroupsGranteeBelongs = false;
/*      */           } else {
/* 4984 */             throw ServiceException.INVALID_REQUEST("invalid value for the include group flag, must be 0 or 1", null);
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     
/* 4990 */     TargetBy targetBy = ra.mTargetIdOrName == null ? null : guessTargetBy(ra.mTargetIdOrName);
/* 4991 */     GranteeSelector.GranteeBy granteeBy = ra.mGranteeIdOrName == null ? null : guessGranteeBy(ra.mGranteeIdOrName);
/*      */     
/* 4993 */     RightCommand.Grants grants = this.prov.getGrants(ra.mTargetType, targetBy, ra.mTargetIdOrName, ra.mGranteeType, granteeBy, ra.mGranteeIdOrName, granteeIncludeGroupsGranteeBelongs);
/*      */     
/*      */ 
/* 4996 */     String format = "%-12.12s %-36.36s %-30.30s %-12.12s %-36.36s %-30.30s %s\n";
/* 4997 */     console.printf(format, new Object[] { "target type", "target id", "target name", "grantee type", "grantee id", "grantee name", "right" });
/* 4998 */     console.printf(format, new Object[] { "------------", "------------------------------------", "------------------------------", "------------", "------------------------------------", "------------------------------", "--------------------" });
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 5007 */     for (RightCommand.ACE ace : grants.getACEs())
/*      */     {
/* 5009 */       RightModifier rightModifier = ace.rightModifier();
/* 5010 */       String rm = rightModifier == null ? "" : String.valueOf(rightModifier.getModifier());
/* 5011 */       console.printf(format, new Object[] { ace.targetType(), ace.targetId(), ace.targetName(), ace.granteeType(), ace.granteeId(), ace.granteeName(), rm + ace.right() });
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 5020 */     console.println();
/*      */   }
/*      */   
/*      */   private void doGrantRight(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 5024 */     RightArgs ra = new RightArgs(args);
/* 5025 */     getRightArgs(ra, true, true);
/*      */     
/* 5027 */     TargetBy targetBy = ra.mTargetIdOrName == null ? null : guessTargetBy(ra.mTargetIdOrName);
/* 5028 */     GranteeSelector.GranteeBy granteeBy = ra.mGranteeIdOrName == null ? null : guessGranteeBy(ra.mGranteeIdOrName);
/*      */     
/* 5030 */     this.prov.grantRight(ra.mTargetType, targetBy, ra.mTargetIdOrName, ra.mGranteeType, granteeBy, ra.mGranteeIdOrName, ra.mSecret, ra.mRight, ra.mRightModifier);
/*      */   }
/*      */   
/*      */   private void doRevokeRight(String[] args) throws ServiceException, ProvUtil.ArgException
/*      */   {
/* 5035 */     RightArgs ra = new RightArgs(args);
/* 5036 */     getRightArgs(ra, true, false);
/*      */     
/* 5038 */     TargetBy targetBy = ra.mTargetIdOrName == null ? null : guessTargetBy(ra.mTargetIdOrName);
/* 5039 */     GranteeSelector.GranteeBy granteeBy = ra.mGranteeIdOrName == null ? null : guessGranteeBy(ra.mGranteeIdOrName);
/*      */     
/* 5041 */     this.prov.revokeRight(ra.mTargetType, targetBy, ra.mTargetIdOrName, ra.mGranteeType, granteeBy, ra.mGranteeIdOrName, ra.mRight, ra.mRightModifier);
/*      */   }
/*      */   
/*      */   private void doGetAuthTokenInfo(String[] args)
/*      */   {
/* 5046 */     String authToken = args[1];
/*      */     try
/*      */     {
/* 5049 */       attrs = AuthToken.getInfo(authToken);
/* 5050 */       List keys = new ArrayList(attrs.keySet());
/* 5051 */       Collections.sort(keys);
/*      */       
/* 5053 */       for (Object k : keys) {
/* 5054 */         String key = k.toString();
/* 5055 */         String value = attrs.get(k).toString();
/*      */         
/* 5057 */         if ("exp".equals(key)) {
/* 5058 */           long exp = Long.parseLong(value);
/* 5059 */           console.format("%s: %s (%s)\n", new Object[] { key, value, DateUtil.toRFC822Date(new Date(exp)) });
/*      */         } else {
/* 5061 */           console.format("%s: %s\n", new Object[] { key, value });
/*      */         }
/*      */       }
/*      */     } catch (AuthTokenException e) { Map attrs;
/* 5065 */       console.println("Unable to parse auth token: " + e.getMessage());
/*      */     }
/*      */     
/* 5068 */     console.println();
/*      */   }
/*      */   
/*      */   private void doUpdatePresenceSessionId(String[] args) throws ServiceException
/*      */   {
/* 5073 */     String idOrName = args[1];
/* 5074 */     String username = args[2];
/* 5075 */     String password = args[3];
/*      */     
/* 5077 */     UCService ucService = lookupUCService(idOrName);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/* 5082 */     String newSessionId = this.prov.updatePresenceSessionId(ucService.getId(), username, password);
/* 5083 */     console.println(newSessionId);
/*      */   }
/*      */   
/*      */   private void doGetAllFreeBusyProviders() throws ServiceException, IOException {
/* 5087 */     FbCli fbcli = new FbCli();
/* 5088 */     for (FbCli.FbProvider fbprov : fbcli.getAllFreeBusyProviders()) {
/* 5089 */       console.println(fbprov.toString());
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetFreeBusyQueueInfo(String[] args) throws ServiceException, IOException {
/* 5094 */     FbCli fbcli = new FbCli();
/* 5095 */     String name = null;
/* 5096 */     if (args.length > 1) {
/* 5097 */       name = args[1];
/*      */     }
/* 5099 */     for (FbCli.FbQueue fbqueue : fbcli.getFreeBusyQueueInfo(name)) {
/* 5100 */       console.println(fbqueue.toString());
/*      */     }
/*      */   }
/*      */   
/*      */   private void doPushFreeBusy(String[] args) throws ServiceException, IOException {
/* 5105 */     FbCli fbcli = new FbCli();
/* 5106 */     Map<String, HashSet<String>> accountMap = new HashMap();
/* 5107 */     for (int i = 1; i < args.length; i++) {
/* 5108 */       String acct = args[i];
/* 5109 */       Account account = this.prov.getAccountById(acct);
/* 5110 */       if (account == null) {
/* 5111 */         throw AccountServiceException.NO_SUCH_ACCOUNT(acct);
/*      */       }
/* 5113 */       String host = account.getMailHost();
/* 5114 */       HashSet<String> accountSet = (HashSet)accountMap.get(host);
/* 5115 */       if (accountSet == null) {
/* 5116 */         accountSet = new HashSet();
/* 5117 */         accountMap.put(host, accountSet);
/*      */       }
/* 5119 */       accountSet.add(acct);
/*      */     }
/* 5121 */     for (String host : accountMap.keySet()) {
/* 5122 */       console.println("pushing to server " + host);
/* 5123 */       fbcli.setServer(host);
/* 5124 */       fbcli.pushFreeBusyForAccounts((Collection)accountMap.get(host));
/*      */     }
/*      */   }
/*      */   
/*      */   private void doPushFreeBusyForDomain(String[] args) throws ServiceException, IOException {
/* 5129 */     lookupDomain(args[1]);
/* 5130 */     FbCli fbcli = new FbCli();
/* 5131 */     for (Server server : this.prov.getAllMailClientServers()) {
/* 5132 */       console.println("pushing to server " + server.getName());
/* 5133 */       fbcli.setServer(server.getName());
/* 5134 */       fbcli.pushFreeBusyForDomain(args[1]);
/*      */     }
/*      */   }
/*      */   
/*      */   private void doPurgeFreeBusyQueue(String[] args) throws ServiceException, IOException {
/* 5139 */     String provider = null;
/* 5140 */     if (args.length > 1) {
/* 5141 */       provider = args[1];
/*      */     }
/* 5143 */     FbCli fbcli = new FbCli();
/* 5144 */     fbcli.purgeFreeBusyQueue(provider);
/*      */   }
/*      */   
/*      */   private void dumpSMIMEConfigs(Map<String, Map<String, Object>> smimeConfigs) throws ServiceException {
/* 5148 */     for (Map.Entry<String, Map<String, Object>> smimeConfig : smimeConfigs.entrySet()) {
/* 5149 */       String configName = (String)smimeConfig.getKey();
/* 5150 */       Map<String, Object> configAttrs = (Map)smimeConfig.getValue();
/*      */       
/* 5152 */       console.println("# name " + configName);
/* 5153 */       dumpAttrs(configAttrs, null);
/* 5154 */       console.println();
/*      */     }
/*      */   }
/*      */   
/*      */   private void doGetConfigSMIMEConfig(String[] args) throws ServiceException {
/* 5159 */     String configName = null;
/* 5160 */     if (args.length > 1) {
/* 5161 */       configName = args[1];
/*      */     }
/*      */     
/* 5164 */     Map<String, Map<String, Object>> smimeConfigs = this.prov.getConfigSMIMEConfig(configName);
/* 5165 */     dumpSMIMEConfigs(smimeConfigs);
/*      */   }
/*      */   
/*      */   private void doGetDomainSMIMEConfig(String[] args) throws ServiceException {
/* 5169 */     String domainName = args[1];
/* 5170 */     Domain domain = lookupDomain(domainName);
/*      */     
/* 5172 */     String configName = null;
/* 5173 */     if (args.length > 2) {
/* 5174 */       configName = args[2];
/*      */     }
/*      */     
/* 5177 */     Map<String, Map<String, Object>> smimeConfigs = this.prov.getDomainSMIMEConfig(domain, configName);
/* 5178 */     dumpSMIMEConfigs(smimeConfigs);
/*      */   }
/*      */   
/*      */   private void doModifyConfigSMIMEConfig(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 5182 */     String configName = args[1];
/* 5183 */     this.prov.modifyConfigSMIMEConfig(configName, getMapAndCheck(args, 2, false));
/*      */   }
/*      */   
/*      */   private void doModifyDomainSMIMEConfig(String[] args) throws ServiceException, ProvUtil.ArgException {
/* 5187 */     String domainName = args[1];
/* 5188 */     Domain domain = lookupDomain(domainName);
/*      */     
/* 5190 */     String configName = args[2];
/* 5191 */     this.prov.modifyDomainSMIMEConfig(domain, configName, getMapAndCheck(args, 3, false));
/*      */   }
/*      */   
/*      */   private void doRemoveConfigSMIMEConfig(String[] args) throws ServiceException {
/* 5195 */     String configName = null;
/* 5196 */     if (args.length > 1) {
/* 5197 */       configName = args[1];
/*      */     }
/*      */     
/* 5200 */     this.prov.removeConfigSMIMEConfig(configName);
/*      */   }
/*      */   
/*      */   private void doRemoveDomainSMIMEConfig(String[] args) throws ServiceException {
/* 5204 */     String domainName = args[1];
/* 5205 */     Domain domain = lookupDomain(domainName);
/*      */     
/* 5207 */     String configName = null;
/* 5208 */     if (args.length > 2) {
/* 5209 */       configName = args[2];
/*      */     }
/*      */     
/* 5212 */     this.prov.removeDomainSMIMEConfig(domain, configName);
/*      */   }
/*      */   
/*      */   private void doHelp(String[] args) {
/* 5216 */     Category cat = null;
/* 5217 */     if ((args != null) && (args.length >= 2)) {
/* 5218 */       String s = args[1].toUpperCase();
/*      */       Category[] arr$;
/* 5220 */       int len$; int i$; try { cat = Category.valueOf(s);
/*      */       } catch (IllegalArgumentException e) {
/* 5222 */         arr$ = Category.values();len$ = arr$.length;i$ = 0; } for (; i$ < len$; i$++) { Category c = arr$[i$];
/* 5223 */         if (c.name().startsWith(s)) {
/* 5224 */           cat = c;
/* 5225 */           break;
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*      */ 
/* 5231 */     if ((args == null) || (args.length == 1) || (cat == null)) {
/* 5232 */       console.println(" zmprov is used for provisioning. Try:");
/* 5233 */       console.println("");
/* 5234 */       for (Category c : Category.values()) {
/* 5235 */         console.printf("     zmprov help %-15s %s\n", new Object[] { c.name().toLowerCase(), c.getDescription() });
/*      */       }
/*      */     }
/*      */     
/*      */ 
/* 5240 */     if (cat != null) {
/* 5241 */       console.println("");
/* 5242 */       for (Command c : Command.values()) {
/* 5243 */         if (c.hasHelp())
/*      */         {
/*      */ 
/* 5246 */           if ((cat == Category.COMMANDS) || (cat == c.getCategory())) {
/* 5247 */             ProvUtil.Command.Via via = c.getVia();
/* 5248 */             console.printf("  %s(%s) %s\n", new Object[] { c.getName(), c.getAlias(), c.getHelp() });
/* 5249 */             if (via == ProvUtil.Command.Via.ldap) {
/* 5250 */               console.printf("    -- NOTE: %s can only be used with \"zmprov -l/--ldap\"\n", new Object[] { c.getName() });
/*      */             }
/* 5252 */             console.printf("\n", new Object[0]);
/*      */           }
/*      */         }
/*      */       }
/* 5256 */       Category.help(cat);
/*      */     }
/* 5258 */     console.println();
/*      */   }
/*      */   
/*      */   public void receiveSoapMessage(PostMethod postMethod, Element envelope)
/*      */   {
/* 5263 */     console.printf("======== SOAP RECEIVE =========\n", new Object[0]);
/*      */     
/* 5265 */     if (this.debugLevel == SoapDebugLevel.high) {
/* 5266 */       Header[] headers = postMethod.getResponseHeaders();
/* 5267 */       for (Header header : headers) {
/* 5268 */         console.println(header.toString().trim());
/*      */       }
/* 5270 */       console.println();
/*      */     }
/*      */     
/* 5273 */     long end = System.currentTimeMillis();
/* 5274 */     console.println(envelope.prettyPrint());
/* 5275 */     console.printf("=============================== (%d msecs)\n", new Object[] { Long.valueOf(end - this.sendStart) });
/*      */   }
/*      */   
/*      */   public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState)
/*      */   {
/* 5280 */     console.println("========== SOAP SEND ==========");
/*      */     
/* 5282 */     if (this.debugLevel == SoapDebugLevel.high) {
/*      */       try {
/* 5284 */         URI uri = postMethod.getURI();
/* 5285 */         console.println(uri.toString());
/*      */       } catch (URIException e) {
/* 5287 */         if (this.verboseMode) {
/* 5288 */           e.printStackTrace(errConsole);
/*      */         } else {
/* 5290 */           console.println("Unable to get request URL, error=" + e.getMessage());
/*      */         }
/*      */       }
/*      */       
/* 5294 */       Header[] headers = postMethod.getRequestHeaders();
/* 5295 */       for (Header header : headers) {
/* 5296 */         console.println(header.toString().trim());
/*      */       }
/* 5298 */       console.println();
/*      */     }
/*      */     
/* 5301 */     this.sendStart = System.currentTimeMillis();
/*      */     
/* 5303 */     console.println(envelope.prettyPrint());
/* 5304 */     console.println("===============================");
/*      */   }
/*      */   
/*      */   private void throwSoapOnly() throws ServiceException {
/* 5308 */     throw ServiceException.INVALID_REQUEST("can only be used with SOAP", null);
/*      */   }
/*      */   
/*      */   private void throwLdapOnly() throws ServiceException {
/* 5312 */     throw ServiceException.INVALID_REQUEST("can only be used with  \"zmprov -l/--ldap\"", null);
/*      */   }
/*      */   
/*      */   private void loadLdapSchemaExtensionAttrs() {
/* 5316 */     if ((this.prov instanceof LdapProv)) {
/* 5317 */       AttributeManager.loadLdapSchemaExtensionAttrs((LdapProv)this.prov);
/*      */     }
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ProvUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */